met*_*eap 23 gcc mingw go glfw cgo
(非常详细的问题报告 - tl;底部是博士!)
我真的更喜欢GLFW到Glut,并希望它的Golang绑定在Windows 64位下使用Go 1.0.1 64位.在Linux下,它的绑定完美无瑕.这在原则上是在Windows下是可行的- GitHub的用户家校会设法来做到这一点,但他是在Win32和他的提示没有解决我的问题呢.但是我确实有一个基于tdm64-gcc-4.6.1的完整而干净的Mingw64设置.
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:
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
Run Code Online (Sandbox Code Playgroud)
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"
Run Code Online (Sandbox Code Playgroud)
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"
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
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...
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?
我已经有一段时间遇到完全相同的问题了,每次我解决上次尝试的挫败感时,我都在研究它。为 go 编译 32 位 glfw 没问题,但 64 位版本让我望而却步。
今天,在阅读了 kneo 的评论后,我尝试了他的解决方案,但无法正常工作。但它让我看到 libglfwdll.a 有 @nn stdcall 后缀,而 libglfw.a 没有。尝试各种 LDFLAGS (-Wl,--kill-at, -Wl,--enable-stdcall-fixup) 没有产生成功的结果,我研究了http://www.willus.com/mingw/yongweiwu_stdcall.html但不能不让它工作。
当我决定查看是否有带有以下错误修复的新版本 glfw (2.7.6) 时,我正准备放弃:
[Win32] Bugfix: A .def file using __stdcall naming conventions was used for the 64-bit DLL on MinGW-w64
Run Code Online (Sandbox Code Playgroud)
长话短说,编译新的 glfw 版本并安装它解决了这个问题,go get github.com/jteeuwen/glfw现在可以正常工作了。
| 归档时间: |
|
| 查看次数: |
4327 次 |
| 最近记录: |