How to use under Windows?
metaleap opened this issue · 7 comments
Hi chsc,
I used gogl for 2 months under Linux and it worked like a charm. Now moving to a Windows dev environment and cannot get glfw to work ( https://github.com/jteeuwen/glfw/issues/9 ) -- however, I did see your screenshot of a successfully running spinning gopher gogl example program -- so somehow it must be possible to run under Windows. How did you pull this off? Did the jteeuwen/glfw package work for you right out of the box after a go-get or did you have to pull some additional tricks? The original glfw.dll was re-built and installed over here, makes no difference.
So not directly a gogl issue -- feel free to close this right away -- but I'm just so curious as to how you managed to create that Windows GLFW app. After a full day of experimenting and trials I've really run out of ideas now. :/
Alternatively, do you remember which Go version you used when building the example under Windows? Was it Go 1 initial release or one of the former weeklies? Who knows, maybe I've just hit a brand-new bug in Go 1.0.1 (just released today)...
Hi metaleap,
cgo has some problems with static linking on windows. I've patched my local version of glfw to use the dynamically linked library of glfw on windows.
Just do the following:
- Create a local copy of glfw for Go via git.
- Add #define GLFW_DLL before every #include < GL/glfw.h > in the following files: callback.h, glfw.go. image.go and vidmode.go.
- Replace -lglfw with -lglfwdll in glfw.go (LDFLAGS) .
- Recompile glfw for go.
- Recompile your glfw sample program.
This works for me. Maybe jteeuwen could modify glfw with some preprocessor hacks to use the dynamically linked version of glfw on windows. It could look like this (just a proposal):
#ifdef _WIN32
#define GLFW_DLL
#endif
#include <GL/glfw.h>
and
#cgo windows LDFLAGS: -lglu32 -lopengl32 -glfwdll
Thanks for those detailed suggestions! Still no luck at my end though -- lots of messages now even during recompilation of go-glfw, all like this: "..._obj\image.cgo2.o: In function _cgo_c3fa7f397da9_Cfunc_glfwReadMemoryImage': C:\Go\src\pkg\github.com\jteeuwen\glfw/image.go:107: undefined reference to
__imp_glfwReadMemoryImage'.
Not sure what else I can do. Seems to work on other Windows machines such as yours. Probably should re-install Windows, har-har... :// anyway thanks much!
Hmm -- just one more set of quick questions about your env out of curiosity:
- did you do this on Win 7 or an earlier version, 32 or 64 bit?
- your glfwdll.a was compiled using 32bit gcc or 64bit gcc?
- your Go distro is the 32bit or 64bit one?
- 2 weeks ago when you posted the Gopher example screenshots, did you use Go 1 or one of the earlier weeklies? (Under Linux, I used to work with some Feb'12 weekly well into April...)
My "undefined reference" errors quoted yesterday were probably just due to a somewhat corrupted (thanks to my fiddling and tweaking) gcc env. Did a fresh MinGW, mingw64 and Go set up this morning and compiled glfwdll for 32 bit this time, yesterday I made it for 64 bit. But this was unnecessary, since the 32bit one can be used with LDFLAGS: -m32 and CFLAGS: -m32. Now I'm back to the "not defined" errors (even with the #define GLFW_DLL etc applied). Go-nuts mailing list says this is a known issue. So wondering which Go version you used as you didn't run into it.
Hey Christian -- could you email me your \go\pkg\win64githubetcpp\glfw.a file by any chance? I cannot build it myself -- see this latest posting https://github.com/jteeuwen/glfw/issues/9#issuecomment-5394247 -- but I presume hopefully maybe I could link to one that was previously successfully built, such as yours. Worth a try.
Email is philipp.schumann@gmail.com -- cheers!
I've tested it with Windows 7 (32bit) and the Go 1 release.
Thanks for the .a file! That explains things... in 32-bit, it is all fairly easy. 64-bit seems to not have fully arrived in the Windows side of mingw/gcc/cgo... :) that would mean your .a file is a 32-bit binary as well, I don't even need to try to link it. :/ thanks though!