本文介绍了通过Windows cgo-> gcc-> ld的DLL链接给出“undefined-reference-to(function)”。错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(非常详细的问题报告 - tl;博士在底部!)

我真的更喜欢GLFW给Glut并希望得到它的在Windows 64位下使用Go 1.0.1 64位。在Linux下,它的工作完美无瑕。这在Windows下原则上是可行的 - GitHub用户chsc ,但他在Win32上,他的提示还没有解决我的问题。然而,我确实有一个基于tdm64-gcc-4.6.1设置的完整而干净的Mingw64。



现在有个奇怪的事情 - 让freeglut绑定工作64位Windows,64位Go 1.0.1 有效 - glfw绑定失败。我想知道为什么,因为它们本质上都使用相同的cgo功能和技巧。

注意我目前有一个自制的一半 - 但基本上正在工作的替换包,它使用LoadLibrary / GetProcAddress调用来暴露Go中的glfw.dll。这工作,但我认为一个硬链接编译的CGO绑定比无数Syscall(),Syscall6(),Syscall9(),Syscall12()等Go func调用更可取。如果Win32和Linux gophers可以这样做,为什么不我们Win64人?



所以这里是我的设置到目前为止:


  1. 我使用应用

  2. 我使用MinGW64成功编译了最新的freeglut和GLFW库作为64位DLL。
  3. Header文件glut.h,freeglut * .h和glfw.h被放置在\ MinGW64 \x86_64-w64-mingw32\include\GL(在gl.h,glaux.h,glu.h旁边)

  4. lib文件libfreeglut.a和libglfwdll.a位于\MinGW64\x86_64-w64-mingw32\lib(位于libglu32.a,libopengl32.a旁边)
  5. >
  6. 64位DLL glfw.dll和freeglut64.dll被放置在\ windows和\ windows \ system32(在opengl32.dll,glu32.dll旁边)

  7. freeglut64.dll和glfw.dll 都可以工作,我相信 - 至少大部分他们的示例程序在安装DLL后执行。

一切都应该到位,对不对?现在先成功绑定(我不需要),freeglut - 当我去获取-x github.com/zombiezen/Go-GLUT/glut 时,所有内容都被构建得很好,而我可以成功创建一个过度窗口,并在.go源文件编译的Windows test.exe中显示一个三角形。感谢-x,去获得显示它构建的内容:

  WORK = C:\ Users \roxor\ AppData \Local\Temp\go-build292908674 
mkdir -p $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\
cd C:\\ \\ Go \src\pkg\github.com\zombiezen\Go-GLUT\glut
C:\ Go\pkg\tool\windows_amd64\cgo.exe -objdir $ WORK \github.com\zombiezen\Go-GLUT\glut\_obj\ - -I $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ glut .go
C:\ Go\pkg\tool\windows_amd64\6c.exe -FVw -I $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj \ -IC:\ Go \pkg\windows_amd64 -o $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_defun.6 -DGOOS_windows -DGOARCH_amd64 $ WORK \ github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_defun.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\zombiezen\Go-GLUT\glut\_obj\ -o $ WORK\github.com\zombiezen\Go-GLUT \glut\_obj\_cgo_main.o -c $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_main.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\zombiezen\Go-GLUT\glut\_obj\ -o $ WORK\github.com\zombiezen\Go-GLUT \glut\_obj\_cgo_export.o -c $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_export.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\zombiezen\Go-GLUT\glut\_obj\ -o $ WORK\github.com\zombiezen\Go-GLUT \glut\_obj\glut.cgo2.o -c $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\glut.cgo2.c
gcc -I 。 -g -O2 -m64 -mthreads -I $ WORK \github.com\zombiezen\Go-GLUT\glut\_obj\ -o $ WORK\github.com\zombiezen\Go-GLUT \glut\_obj\support.o -c .\support.c
gcc -I。 -g -O2 -m64 -mthreads -o $ WORK \github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_.o $ WORK\github.com\zombiezen\Go- GLUT \glut\_obj\_cgo_main.o $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_export.o $ WORK\github.com\zombiezen\ Go-GLUT\glut\_obj\glut.cgo2.o $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\support.o -lfreeglut
C: \ Go\pkg\tool\windows_amd64\cgo.exe -objdir $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -dynimport $ WORK\github。 com_\\zombiezen\Go-GLUT\glut\_obj\_cgo_.o -dynout $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_import.c
C:\ Go\pkg\tool\windows_amd64\6c.exe -FVw -I $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -IC :\Go\pkg\windows_amd64 -o $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_import.6 -DGOOS_windows -DGOARCH_amd64 $ WORK\github.com\zombiezen\Go-GLUT\glut \_obj\_cgo_import.c
gcc -I。 -g -O2 -m64 -mthreads -o $ WORK \github.com\zombiezen\Go-GLUT\glut\_obj\_all.o $ WORK\github.com\zombiezen\Go- GLUT \glut\_obj\_cgo_export.o $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\glut.cgo2.o $ WORK\github.com\zombiezen \ GO-GLUT \glut\_obj\support.o -Wl,-r -nostdlib -lgcc -lmingwex -lmingw32
C:\ Go\pkg\tool\windows_amd64\6g .exe -o $ WORK \github.com\zombiezen\Go-GLUT\glut\_obj\_go_.6 -p github.com/zombiezen/Go-GLUT/glut -D _ / C_ / Go /src/pkg/github.com/zombiezen/Go-GLUT/glut -I $ WORK $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_gotypes.go $ WORK\ github.com\zombiezen\Go-GLUT\glut\_obj\glut.cgo1.go
C:\ Go\pkg\tool\windows_amd64\pack.exe grc $ WORK \github.com\zombiezen\Go-GLUT\glut.a $ WORK\github.com\\ zombiezen \Go-GLUT\glut\_obj\_go_.6 $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_import.6 $ WORK\github.com \zombiezen\Go-GLUT\glut\_obj\_cgo_defun.6 $ WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_all.o
mkdir -p C:\ Go\pkg\windows_amd64\github.com\zombiezen\Go-GLUT\
cp $ WORK\github.com\zombiezen\Go-GLUT\ glut.a C:\ Go\pkg\windows_amd64\github.com\zombiezen\Go-GLUT\glut.a

为了达到这一点,我必须稍微修改glut.go,如下所示:

  // #cgo windows LDFLAGS:-lfreeglut 
// #include< stdlib.h>
// #includesupport.h
importC

因此,总结一下,这种构建方式很好,可以从Go中导入和链接并用于代码中。



现在用于GLFW。 GO文件与glut.go非常相似:

  //#cgo windows LDFLAGS:-lglfwdll -lglu32 -lopengl32 
//#include >
//#define GLFW_DLL
//#include< GL / glfw.h>
导入C

#define GLFW_DLL使得。然而,以下是 go get -x github.com/jteeuwen/glfw 的输出:

  WORK = C:\ Users \roxor\AppData\Local\Temp\go-build499107422 
mkdir -p $ WORK\github.com\jteeuwen\glfw\_obj\
cd C:\ Go \src\pkg\github.com\jteeuwen\glfw
C:\ Go\pkg\tool\windows_amd64\cgo.exe -objdir $ WORK \github.com\jteeuwen\glfw\_obj\ - -I $ WORK\github.com\jteeuwen\glfw\_obj\ callback.go glfw.go image.go vidmode。 go
C:\ Go\pkg\tool\windows_amd64\6c.exe -FVw -I $ WORK\github.com\jteeuwen\glfw\_obj\ -IC:\\ \\ Go \pkg\windows_amd64 -o $ WORK\github.com\jteeuwen\glfw\_obj\_cgo_defun.6 -DGOOS_windows -DGOARCH_amd64 $ WORK \github.com\jteeuwen\glfw\ _obj\_cgo_defun.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\jteeuwen\glfw\_obj\ -o $ WORK\github.com\jteeuwen\glfw\_obj\_cgo_main。 o -c $ WORK \github.com\jteeuwen\glfw\_obj\_cgo_main.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\jteeuwen\glfw\_obj\ -o $ WORK\github.com\jteeuwen\glfw\_obj\_cgo_export。 o -c $ WORK \github.com\jteeuwen\glfw\_obj\_cgo_export.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\jteeuwen\glfw\_obj\ -o $ WORK\github.com\jteeuwen\glfw\_obj\callback。 cgo2.o -c $ WORK \github.com\jteeuwen\glfw\_obj\callback.cgo2.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\jteeuwen\glfw\_obj\ -o $ WORK\github.com\jteeuwen\glfw\_obj\glfw。 cgo2.o -c $ WORK \github.com\jteeuwen\glfw\_obj\glfw.cgo2.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\jteeuwen\glfw\_obj\ -o $ WORK\github.com\jteeuwen\glfw\_obj\image。 cgo2.o -c $ WORK \github.com\jteeuwen\glfw\_obj\image.cgo2.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\jteeuwen\glfw\_obj\ -o $ WORK\github.com\jteeuwen\glfw\_obj\vidmode。 cgo2.o -c $ WORK \github.com\jteeuwen\glfw\_obj\vidmode.cgo2.c
gcc -I。 -g -O2 -m64 -mthreads -I $ WORK \github.com\jteeuwen\glfw\_obj\ -o $ WORK\github.com\jteeuwen\glfw\_obj\callback。 o -c .\callback.c
gcc -I。 -g -O2 -m64 -mthreads -o $ WORK \github.com\jteeuwen\glfw\_obj\_cgo_.o $ WORK\github.com\jteeuwen\glfw\_obj\_cgo_main .o $ WORK \github.com\jteeuwen\glfw\_obj\_cgo_export.o $ WORK\github.com\jteeuwen\glfw\_obj\callback.cgo2.o $ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o $ WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.o $ WORK\github.com\\ \\ jteeuwen\glfw\_obj\vidmode.cgo2.o $ WORK \github.com\jteeuwen\glfw\_obj\callback.o -lglfwdll -lglu32 -lopengl32
#github.com / jteeuwen / glfw
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetNumberOfProcessors'中:
C:\ Go \src \pkg\github.com\jteeuwen\glfw / glfw.go:39:对`__imp_glfwGetNumberOfProcessors'
$的未定义引用WORK \github.com\jt eeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetKey':
C:\ Go \ src \pkg\github.com\jteeuwen\glfw / glfw。去:51:未定义的引用'__imp_glfwGetKey'
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwSetTime':
C: \ Go \src\pkg\github.com\jteeuwen\glfw / glfw.go:60:对`__imp_glfwSetTime'的未定义引用
$ WORK \github.com\jteeuwen\glfw \_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwExtensionSupported':
C:\ Go \src\pkg\github.com\jteeuwen\glfw / glfw.go:71:未定义的引用'__imp_glfwExtensionSupported'
$ WORK \github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数中`_cgo_680190d759a2_Cfunc_glfwPollEvents':
C:\ Go\\ \\ src \pkg\github.com\jteeuwen\glfw / glfw.go:80:unde对`__imp_glfwPollEvents'
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o的罚款引用:在函数`_cgo_680190d759a2_Cfunc_glfwGetMousePos':
C:\ Go \\ \\ src \pkg\github.com\jteeuwen\glfw / glfw.go:90:对`__imp_glfwGetMousePos'
$的未定义引用WORK \github.com\jteeuwen\glfw\_obj\\ \\ glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetJoystickParam'中:
C:\ Go \src\pkg\github.com\jteeuwen\glfw /glfw.go:102:undefined指向` __imp_glfwGetJoystickParam'
$ WORK \github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:函数中`_cgo_680190d759a2_Cfunc_glfwGetProcAddress':
C:\ Go\src\ pkg\github.com\jteeuwen\glfw / glfw.go:112:未定义的引用__imp_glfwGetProcAddress'
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2 .o:在函数中_cgo_680190d759a2_Cfunc_glfwGetGL版本':
C:\ Go \ src \pkg\github.com\jteeuwen\glfw / glfw.go:123:对`__imp_glfwGetGLVersion'的未定义引用
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:函数`_cgo_680190d759a2_Cfunc_glfwSetMouseWheel':
C:\ Go \src\pkg\github.com\jteeuwen\\ \\ glfw / glfw.go:133:未定义引用`__imp_glfwSetMouseWheel'
$ WORK \github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetJoystickPos'中:
C:\ Go \src\pkg\github.com\jteeuwen\glfw / glfw.go:148:未定义的对`__imp_glfwGetJoystickPos'的引用
$ WORK \github.com\\ \\ jteeuwen \glfw \_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwOpenWindow'中:
C:\ Go \ src\pkg\github.com\jteeuwen\glfw / glfw .go:168:对'__imp_glfwOpenWindow'
$ WORK'\\github.com的未定义引用\\ jteeuwen \glfw \_obj\glfw.cgo2.o:在函数中`_cgo_680190d759a2_Cfunc_glfwSetMousePos':
C:\ Go \ src\pkg\github.com\jteeuwen\glfw / glfw .go:178:未定义引用`__imp_glfwSetMousePos'
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:函数中`_cgo_680190d759a2_Cfunc_glfwSwapInterval':
C :\ Go \src\pkg\github.com\jteeuwen\glfw / glfw.go:188:未定义的对`__imp_glfwSwapInterval'的引用
$ WORK\github.com\jteeuwen\ glfw \_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetMouseButton':
C:\ Go \src\pkg\github.com\jteeuwen\glfw / glfw.go:209 :未定义的引用'__imp_glfwGetMouseButton'
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:函数`_cgo_680190d759a2_Cfunc_glfwSetWindowTitle':
C:\ Go \src\pkg\github.com\jteeuwen \\ glfw / glfw.go:218:未定义的引用__imp_glfwSetWindowTitle
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:函数`_cgo_680190d759a2_Cfunc_glfwGetVideoModes':
C:\ Go\src\pkg\github.com\jteeuwen\glfw / glfw.go:231:未定义的对`__imp_glfwGetVideoModes'的引用
$ WORK \github.com\\ \\ jteeuwen \glfw \_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetJoystickButtons'中:
C:\ Go\src\pkg\github.com\jteeuwen\glfw / glfw .go:246:未定义引用'__imp_glfwGetJoystickButtons'
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwRestoreWindow'中:
C :\ Go \src\pkg\github.com\jteeuwen\glfw / glfw.go:255:未定义的对`__imp_glfwRestoreWindow'的引用
$ WORK\github.com\jteeuwen\ glfw \_obj\glfw.cgo2.o:功能离子`_cgo_680190d759a2_Cfunc_glfwInit':
C:\ Go\src\pkg\github.com\jteeuwen\glfw / glfw.go:265:未定义的对`__imp_glfwInit'的引用
$ WORK \github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数中`_cgo_680190d759a2_Cfunc_glfwSwapBuffers':
C:\ Go \src\pkg\github.com\ jteeuwen\glfw / glfw.go:274:未定义引用`__imp_glfwSwapBuffers'
$ WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数中_cgo_680190d759a2_Cfunc_glfwGetMouseWheel' :
C:\ Go \ src \pkg\github.com\jteeuwen\glfw / glfw.go:284:对`__imp_glfwGetMouseWheel'
$ WORK \ github的未定义引用。 com \jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwIconifyWindow'中:
C:\ Go\src\pkg\github.com\jteeuwen\glfw /glfw.go:293:对'__imp_glfwIconifyWindow'
的未定义引用$ WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwWaitEvents'中:
C:\ Go\src\pkg\github.com \ jteeuwen\glfw / glfw.go:302:对`__imp_glfwWaitEvents'
$的未定义引用\\ WORK \ github.com \jteeuwen\glfw\_obj\glfw.cgo2.o:在函数` _cgo_680190d759a2_Cfunc_glfwSetWindowPos':
C:\ Go \ src\pkg\github.com\jteeuwen\glfw / glfw.go:312:对__imp_glfwSetWindowPos的未定义引用
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetWindowSize'中:
C:\ Go\src\pkg\github.com\jteeuwen\\ \\ glfw / glfw.go:322:对`__imp_glfwGetWindowSize'
$的未定义引用\\ $ WORK \ github.com \jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwDisable'中:
C:\ Go \src\pkg\github.com\\ jteeuwen\glfw / glfw.go:332:未定义引用`__imp_glfwDisable'
$ WORK \github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetWindowParam' :
C:\ Go \ src \pkg\github.com\jteeuwen\glfw / glfw.go:344:对`__imp_glfwGetWindowParam'
$ WORK \ github的未定义引用。 com \jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwCloseWindow'中:
C:\ Go\src\pkg\github.com\jteeuwen\glfw /glfw.go:353:未定义引用`__imp_glfwCloseWindow'
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwOpenWindowHint'中:
C:\ Go \src\pkg\github.com\jteeuwen\glfw / glfw.go:363:对__imp_glfwOpenWindowHint的未定义引用
$ WORK\github.com\jteeuwen \glfw\_obj\glfw.cgo2.o:在函数中_ cgo_680190d759a2_Cfunc_glfwSleep':
C:\ Go \ src\pkg\github.com\jteeuwen\glfw / glfw.go:372:对'__imp_glfwSleep'的未定义引用
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwEnable'中:
C:\ Go \src\pkg\github.com\jteeuwen\\ \\ glfw / glfw.go:382:对`__imp_glfwEnable'
$的未定义引用WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwSetWindowSize'中:
C:\ Go \src\pkg\github.com\jteeuwen\glfw / glfw.go:392:未定义的对`__imp_glfwSetWindowSize'的引用
$ WORK \github.com\\ \\ jteeuwen \glfw \_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwTerminate'中:
C:\ Go \ src\pkg\github.com\jteeuwen\glfw / glfw .go:411:未定义引用'__imp_glfwTerminate'
$ WORK \ github.com \\ jteeuwen \glfw \_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetDesktopMode'中:
C:\ Go\src\pkg\github.com\jteeuwen\glfw / glfw .go:420:未定义引用'__imp_glfwGetDesktopMode'
$ WORK \ github.com\jteeuwen\glfw\_obj\glfw.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwGetTime'中:
C :\ Go \src\pkg\github.com\jteeuwen\glfw / glfw.go:429:对`__imp_glfwGetTime'的未定义引用
$ WORK\github.com\jteeuwen\ glfw \_obj\image.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwFreeImage'中:
C:\ Go \src\pkg\github.com\jteeuwen\glfw / image.go:38 :`__imp_glfwFreeImage'的未定义引用
$ WORK \github.com\jteeuwen\glfw\_obj\image.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwReadImage'中:
C:\ Go \src\pkg\github.com\jteeuwen\glfw / image.g o:52:未定义引用'__imp_glfwReadImage'
$ WORK \ github.com\jteeuwen\glfw\_obj\image.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwLoadTextureImage2D'中:
C: \ Go \src\pkg\github.com\jteeuwen\glfw/ image.go:65:未定义的对`__imp_glfwLoadTextureImage2D'的引用
$ WORK \github.com\jteeuwen\glfw \_obj\image.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwLoadMemoryTexture2D':
C:\ Go \ src\pkg\github.com\jteeuwen\glfw / image.go:78:未定义的引用`__imp_glfwLoadMemoryTexture2D'
$ WORK \ github.com\jteeuwen\glfw\_obj\image.cgo2.o:在函数`_cgo_680190d759a2_Cfunc_glfwLoadTexture2D':
C:\ Go\\ \\ src\pkg\github.com\jteeuwen\glfw / image.go:91:未定义的对`__imp_glfwLoadTexture2D'的引用
$ WORK \github.com\jteeuwen\glfw\_obj\\ \\ image.cgo2.o:在函数中_ cgo_680190d759a2_Cfunc_glfwReadMemoryImage':
C:\ Go \ src\pkg\github.com\jteeuwen\glfw / image.go:107:对'__imp_glfwReadMemoryImage'的未定义引用
$ WORK \ github.com\jteeuwen\glfw\_obj\callback.o:在函数`setWindowSizeCB'中:
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:9 :'__imp_glfwSetWindowSizeCallback'
$ WORK \github.com\jteeuwen\glfw\_obj\callback.o的未定义引用:函数`setWindowCloseCB':
C:/ Go / src / pkg / github.com / jteeuwen / glfw / callback.c:14:对`__imp_glfwSetWindowCloseCallback'
$的未定义引用:WORK \github.com\jteeuwen\glfw\_obj\callback.o:In function `setWindowRefreshCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:19:未定义引用'__imp_glfwSetWindowRefreshCallback'
$ WORK \github.com\ jteeuwen\glfw\_obj\callback.o:在函数`setMouseButtonCB'中:
C :/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:24:对'__imp_glfwSetMouseButtonCallback'的未定义引用
$ WORK \github.com\jteeuwen\glfw\_obj\ callback.o:在函数`setMousePosCB'中:
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:29:对`__imp_glfwSetMousePosCallback'的未定义引用
$ WORK \\ \\ github.com \jteeuwen\glfw\_obj\callback.o:函数`setMouseWheelCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c: 34:未定义引用'__imp_glfwSetMouseWheelCallback'
$ WORK\github.com\jteeuwen\glfw\_obj\callback.o:在函数`setKeyCB'中:
C:/ Go / src /pkg/github.com/jteeuwen/glfw/callback.c:39:未定义引用'__imp_glfwSetKeyCallback'
$ WORK \github.com\jteeuwen\glfw\_obj\callback.o:In函数`setCharCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:44:对`__imp_glfwSetCharCallback'的未定义引用
collect2:ld返回1退出状态

是的,相同的错误,并且在构建过程中相当晚。注意,如果没有定义#define GLFW_DLL,除非没有__imp_前缀,我会得到基本相同的输出 - 静态链接既不会鼓励Go,也不适合这种特殊用例。

现在,当gcc抱怨未定义的引用时,从我的谷歌可能有各种各样的原因... ...
$ b


  • 无法找到DLL的错误 - 它们位于适当的位置,对于freeglut64.dll有效

  • 它无法找到.a库的失败 - 他们在适当的位置,libfreeglut.a可以工作,如果我将-lglfwdll更改为-lblafoobar,那么gcc会提前失败并正确地抱怨blafoobar not found - 因此它 找到libglfwdll .a。

  • 库依赖关系的顺序?我尝试了-lglfwdll作为第一个lib(在-lglu32 -lopengl32之前)和最后一个(在这两个之后),没有区别。

  • 是Golang glfw绑定错误吗?不要这么想,适用于其他人,包括Windows下的chsc(32位)



TL; DR - 下Windows 64位,Go 1.0.1 64位完全修补程序,CGO成功生成内容以供GCC freeglut和glfw使用。 GCC然后乐于吃这些东西来建立freeglut绑定,但是拒绝它用于构建glfw绑定,所有C.funcs()都有未定义的引用。 libfreeglut和libglfwdll都正确构建并安装为正确定位的64位DLL和.h / .a库。原因是什么?

解决方案

Go,GLFW和Mingw-w64的最新版本不再是问题。 p>

(Very detailed problem report -- tl;dr at the bottom!)

I really prefer GLFW to Glut and want to get its Golang binding working under Windows 64-bit with Go 1.0.1 64-bit. Under Linux, the binding it works flawlessly. This is in principle doable under Windows -- GitHub user chsc has managed to do so, but he's on Win32 and his tips didn't resolve my issues yet. However I do have a complete and clean Mingw64 set up based on tdm64-gcc-4.6.1.

Now here's the strange thing -- getting the freeglut binding to work under 64-bit Windows, 64-bit Go 1.0.1 works -- the glfw binding fails for me. I want to figure out why, as they essentially both use the same cgo features and techniques.

Note I currently have a self-made half-baked but essentially working replacement package in place that uses LoadLibrary/GetProcAddress calls to expose glfw.dll in Go. This works but I think a hard-linked compiled-in CGO binding would be more desirable than countless Syscall(), Syscall6(), Syscall9(), Syscall12() etc Go func invocations. If Win32 and Linux gophers can have this, why not us Win64 folks?

So here's my setup so far:

  1. I have a Golang build with three patches to make lib linking work with cgo applied
  2. I have successfully compiled the newest freeglut and GLFW libraries as 64-bit DLLs using MinGW64.
  3. Header files glut.h, freeglut*.h and glfw.h are placed in \MinGW64\x86_64-w64-mingw32\include\GL (next to gl.h, glaux.h, glu.h)
  4. Lib files libfreeglut.a and libglfwdll.a are placed in \MinGW64\x86_64-w64-mingw32\lib (next to libglu32.a, libopengl32.a)
  5. 64-bit DLLs glfw.dll and freeglut64.dll are placed in \windows and \windows\system32 (next to opengl32.dll, glu32.dll)
  6. freeglut64.dll and glfw.dll both work, I believe -- at least most of their example programs do after installing the DLLs.

Everything should be in place, right? Now first for the successful binding (that I don't need), freeglut -- when I go get -x github.com/zombiezen/Go-GLUT/glut, all is built just fine and I can successfully create a glut window and show a triangle in a Windows test.exe compiled from a .go source file. Thanks to -x, go get shows what it does to build:

WORK=C:\Users\roxor\AppData\Local\Temp\go-build292908674
mkdir -p $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\
cd C:\Go\src\pkg\github.com\zombiezen\Go-GLUT\glut
C:\Go\pkg\tool\windows_amd64\cgo.exe -objdir $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -- -I $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ glut.go
C:\Go\pkg\tool\windows_amd64\6c.exe -FVw -I $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -I C:\Go\pkg\windows_amd64 -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_defun.6 -DGOOS_windows -DGOARCH_amd64 $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_defun.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_main.o -c $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_main.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_export.o -c $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_export.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\glut.cgo2.o -c $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\glut.cgo2.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\support.o -c .\support.c
gcc -I . -g -O2 -m64 -mthreads -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_.o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_main.o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_export.o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\glut.cgo2.o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\support.o -lfreeglut
C:\Go\pkg\tool\windows_amd64\cgo.exe -objdir $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -dynimport $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_.o -dynout $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_import.c
C:\Go\pkg\tool\windows_amd64\6c.exe -FVw -I $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\ -I C:\Go\pkg\windows_amd64 -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_import.6 -DGOOS_windows -DGOARCH_amd64 $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_import.c
gcc -I . -g -O2 -m64 -mthreads -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_all.o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_export.o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\glut.cgo2.o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\support.o -Wl,-r -nostdlib -lgcc -lmingwex -lmingw32
C:\Go\pkg\tool\windows_amd64\6g.exe -o $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_go_.6 -p github.com/zombiezen/Go-GLUT/glut -D _/C_/Go/src/pkg/github.com/zombiezen/Go-GLUT/glut -I $WORK $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_gotypes.go $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\glut.cgo1.go
C:\Go\pkg\tool\windows_amd64\pack.exe grc $WORK\github.com\zombiezen\Go-GLUT\glut.a $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_go_.6 $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_import.6 $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_cgo_defun.6 $WORK\github.com\zombiezen\Go-GLUT\glut\_obj\_all.o
mkdir -p C:\Go\pkg\windows_amd64\github.com\zombiezen\Go-GLUT\
cp $WORK\github.com\zombiezen\Go-GLUT\glut.a C:\Go\pkg\windows_amd64\github.com\zombiezen\Go-GLUT\glut.a

To get to this point, I had to slightly modify glut.go as follows:

// # include <GL/glut.h>
// #cgo windows LDFLAGS: -lfreeglut
// #include <stdlib.h>
// #include "support.h"
import "C"

So, to summarize, this builds fine, can be imported and linked from Go and used in code.

Now for GLFW. The GO file reads extremely similar to glut.go:

//#cgo windows LDFLAGS: -lglfwdll -lglu32 -lopengl32
//#include <stdlib.h>
//#define GLFW_DLL
//#include <GL/glfw.h>
import "C"

The #define GLFW_DLL is so that no static linking happens. Here's the output of go get -x github.com/jteeuwen/glfw however:

WORK=C:\Users\roxor\AppData\Local\Temp\go-build499107422
mkdir -p $WORK\github.com\jteeuwen\glfw\_obj\
cd C:\Go\src\pkg\github.com\jteeuwen\glfw
C:\Go\pkg\tool\windows_amd64\cgo.exe -objdir $WORK\github.com\jteeuwen\glfw\_obj\ -- -I $WORK\github.com\jteeuwen\glfw\_obj\ callback.go glfw.go image.go vidmode.go
C:\Go\pkg\tool\windows_amd64\6c.exe -FVw -I $WORK\github.com\jteeuwen\glfw\_obj\ -I C:\Go\pkg\windows_amd64 -o $WORK\github.com\jteeuwen\glfw\_obj\_cgo_defun.6 -DGOOS_windows -DGOARCH_amd64 $WORK\github.com\jteeuwen\glfw\_obj\_cgo_defun.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\jteeuwen\glfw\_obj\ -o $WORK\github.com\jteeuwen\glfw\_obj\_cgo_main.o -c $WORK\github.com\jteeuwen\glfw\_obj\_cgo_main.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\jteeuwen\glfw\_obj\ -o $WORK\github.com\jteeuwen\glfw\_obj\_cgo_export.o -c $WORK\github.com\jteeuwen\glfw\_obj\_cgo_export.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\jteeuwen\glfw\_obj\ -o $WORK\github.com\jteeuwen\glfw\_obj\callback.cgo2.o -c $WORK\github.com\jteeuwen\glfw\_obj\callback.cgo2.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\jteeuwen\glfw\_obj\ -o $WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o -c $WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\jteeuwen\glfw\_obj\ -o $WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.o -c $WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\jteeuwen\glfw\_obj\ -o $WORK\github.com\jteeuwen\glfw\_obj\vidmode.cgo2.o -c $WORK\github.com\jteeuwen\glfw\_obj\vidmode.cgo2.c
gcc -I . -g -O2 -m64 -mthreads -I $WORK\github.com\jteeuwen\glfw\_obj\ -o $WORK\github.com\jteeuwen\glfw\_obj\callback.o -c .\callback.c
gcc -I . -g -O2 -m64 -mthreads -o $WORK\github.com\jteeuwen\glfw\_obj\_cgo_.o $WORK\github.com\jteeuwen\glfw\_obj\_cgo_main.o $WORK\github.com\jteeuwen\glfw\_obj\_cgo_export.o $WORK\github.com\jteeuwen\glfw\_obj\callback.cgo2.o $WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o $WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.o $WORK\github.com\jteeuwen\glfw\_obj\vidmode.cgo2.o $WORK\github.com\jteeuwen\glfw\_obj\callback.o -lglfwdll -lglu32 -lopengl32
# github.com/jteeuwen/glfw
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetNumberOfProcessors':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:39: undefined reference to `__imp_glfwGetNumberOfProcessors'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetKey':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:51: undefined reference to `__imp_glfwGetKey'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwSetTime':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:60: undefined reference to `__imp_glfwSetTime'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwExtensionSupported':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:71: undefined reference to `__imp_glfwExtensionSupported'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwPollEvents':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:80: undefined reference to `__imp_glfwPollEvents'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetMousePos':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:90: undefined reference to `__imp_glfwGetMousePos'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetJoystickParam':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:102: undefined reference to `__imp_glfwGetJoystickParam'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetProcAddress':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:112: undefined reference to `__imp_glfwGetProcAddress'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetGLVersion':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:123: undefined reference to `__imp_glfwGetGLVersion'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwSetMouseWheel':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:133: undefined reference to `__imp_glfwSetMouseWheel'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetJoystickPos':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:148: undefined reference to `__imp_glfwGetJoystickPos'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwOpenWindow':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:168: undefined reference to `__imp_glfwOpenWindow'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwSetMousePos':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:178: undefined reference to `__imp_glfwSetMousePos'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwSwapInterval':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:188: undefined reference to `__imp_glfwSwapInterval'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetMouseButton':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:209: undefined reference to `__imp_glfwGetMouseButton'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwSetWindowTitle':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:218: undefined reference to `__imp_glfwSetWindowTitle'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetVideoModes':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:231: undefined reference to `__imp_glfwGetVideoModes'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetJoystickButtons':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:246: undefined reference to `__imp_glfwGetJoystickButtons'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwRestoreWindow':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:255: undefined reference to `__imp_glfwRestoreWindow'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwInit':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:265: undefined reference to `__imp_glfwInit'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwSwapBuffers':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:274: undefined reference to `__imp_glfwSwapBuffers'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetMouseWheel':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:284: undefined reference to `__imp_glfwGetMouseWheel'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwIconifyWindow':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:293: undefined reference to `__imp_glfwIconifyWindow'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwWaitEvents':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:302: undefined reference to `__imp_glfwWaitEvents'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwSetWindowPos':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:312: undefined reference to `__imp_glfwSetWindowPos'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetWindowSize':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:322: undefined reference to `__imp_glfwGetWindowSize'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwDisable':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:332: undefined reference to `__imp_glfwDisable'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetWindowParam':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:344: undefined reference to `__imp_glfwGetWindowParam'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwCloseWindow':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:353: undefined reference to `__imp_glfwCloseWindow'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwOpenWindowHint':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:363: undefined reference to `__imp_glfwOpenWindowHint'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwSleep':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:372: undefined reference to `__imp_glfwSleep'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwEnable':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:382: undefined reference to `__imp_glfwEnable'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwSetWindowSize':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:392: undefined reference to `__imp_glfwSetWindowSize'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwTerminate':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:411: undefined reference to `__imp_glfwTerminate'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetDesktopMode':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:420: undefined reference to `__imp_glfwGetDesktopMode'
$WORK\github.com\jteeuwen\glfw\_obj\glfw.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwGetTime':
C:\Go\src\pkg\github.com\jteeuwen\glfw/glfw.go:429: undefined reference to `__imp_glfwGetTime'
$WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwFreeImage':
C:\Go\src\pkg\github.com\jteeuwen\glfw/image.go:38: undefined reference to `__imp_glfwFreeImage'
$WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwReadImage':
C:\Go\src\pkg\github.com\jteeuwen\glfw/image.go:52: undefined reference to `__imp_glfwReadImage'
$WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwLoadTextureImage2D':
C:\Go\src\pkg\github.com\jteeuwen\glfw/image.go:65: undefined reference to `__imp_glfwLoadTextureImage2D'
$WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwLoadMemoryTexture2D':
C:\Go\src\pkg\github.com\jteeuwen\glfw/image.go:78: undefined reference to `__imp_glfwLoadMemoryTexture2D'
$WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwLoadTexture2D':
C:\Go\src\pkg\github.com\jteeuwen\glfw/image.go:91: undefined reference to `__imp_glfwLoadTexture2D'
$WORK\github.com\jteeuwen\glfw\_obj\image.cgo2.o: In function `_cgo_680190d759a2_Cfunc_glfwReadMemoryImage':
C:\Go\src\pkg\github.com\jteeuwen\glfw/image.go:107: undefined reference to `__imp_glfwReadMemoryImage'
$WORK\github.com\jteeuwen\glfw\_obj\callback.o: In function `setWindowSizeCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:9: undefined reference to `__imp_glfwSetWindowSizeCallback'
$WORK\github.com\jteeuwen\glfw\_obj\callback.o: In function `setWindowCloseCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:14: undefined reference to `__imp_glfwSetWindowCloseCallback'
$WORK\github.com\jteeuwen\glfw\_obj\callback.o: In function `setWindowRefreshCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:19: undefined reference to `__imp_glfwSetWindowRefreshCallback'
$WORK\github.com\jteeuwen\glfw\_obj\callback.o: In function `setMouseButtonCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:24: undefined reference to `__imp_glfwSetMouseButtonCallback'
$WORK\github.com\jteeuwen\glfw\_obj\callback.o: In function `setMousePosCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:29: undefined reference to `__imp_glfwSetMousePosCallback'
$WORK\github.com\jteeuwen\glfw\_obj\callback.o: In function `setMouseWheelCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:34: undefined reference to `__imp_glfwSetMouseWheelCallback'
$WORK\github.com\jteeuwen\glfw\_obj\callback.o: In function `setKeyCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:39: undefined reference to `__imp_glfwSetKeyCallback'
$WORK\github.com\jteeuwen\glfw\_obj\callback.o: In function `setCharCB':
C:/Go/src/pkg/github.com/jteeuwen/glfw/callback.c:44: undefined reference to `__imp_glfwSetCharCallback'
collect2: ld returned 1 exit status

Yes, it's a mouthful -- but essentially just always the same error, and fairly late in the build procedure. Notice if #define GLFW_DLL isn't defined, I get essentially the same output except without the __imp_ prefixes -- and static linking is neither encourage for Go nor is it desirable for this particular use-case.

Now, when gcc complains about "undefined reference to", from what I google there could be various reasons...

  • it cannot be failure to find the DLL's -- they're in the appropriate places and for freeglut64.dll it works
  • it cannot be failure to find the .a libs -- they're in the appropriate places, and libfreeglut.a works, and if I change -lglfwdll to -lblafoobar then gcc fails much earlier and rightly complains "blafoobar not found" -- so it does find libglfwdll.a.
  • order of lib dependencies? I tried -lglfwdll as the first lib (before -lglu32 -lopengl32) and as the last (after those two), no difference.
  • is the Golang glfw binding faulty? Don't think so, works for others, including under Windows for chsc (32-bit though)

TL;DR -- under Windows 64-bit, Go 1.0.1 64-bit fully patched, CGO successfully generates stuff to feed into GCC for both freeglut and glfw. GCC then happily eats that stuff to build the freeglut binding, but rejects it for building the glfw binding, with "undefined reference to" for all C.funcs(). Both libfreeglut and libglfwdll are correctly built and installed as 64-bit DLLs and .h/.a libs correctly located. What could be the cause?

解决方案

No longer an issue with the newest releases of Go, GLFW and Mingw-w64.

这篇关于通过Windows cgo-&gt; gcc-&gt; ld的DLL链接给出“undefined-reference-to(function)”。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 15:56