I ported my CGO-using project to windows, and found that the -ldl flag that is needed on darwin and linux (for dynamic code loading) cannot also be used on windows. Its presence causes my project build to fail.
In order to change the LDFLAG list, I tried putting an #ifdef __APPLE__ or #ifdef _WIN32 / #ifdef __linux__ around the #cgo LDFLAGS in order to change the flags to be platform specific, but that failed gloriously (the #ifdefs just seemed to be ignored). So I ended up creating three copies of the golua.go, one for each platform, using the filename based mechanism. Hence now I have: golua_darwin.go, golua_windows.go, and golua_linux.go. While this builds, its a bit of a code smell/maintenance burden, since except for the one line difference between `#cgo LDFLAGS: -lm -ldl` versus `#cgo LDFLAGS: -lm`, there is no other difference between the three golua_*.go files for each OS. My question: is there a easier way to adapt the LDFLAGS to the operating system? If I port to solaris/illumos/other OS, I'd rather not have to make a 4th/5th copy of the golua.go file, just to change a flag. Specifics to help visualize the situation: https://github.com/gijit/gi/blob/windows/vendor/github.com/glycerine/golua/lua/golua_darwin.go#L5 has: /* #cgo CFLAGS: -I ${SRCDIR}/../../../LuaJIT/LuaJIT/src #cgo LDFLAGS: -lm -ldl #include <lua.h> #include <lualib.h> #include <stdlib.h> */ import "C" https://github.com/gijit/gi/blob/windows/vendor/github.com/glycerine/golua/lua/golua_windows.go#L5 has: /* #cgo CFLAGS: -I ${SRCDIR}/../../../LuaJIT/LuaJIT/src #cgo LDFLAGS: -lm #include <lua.h> #include <lualib.h> #include <stdlib.h> */ import "C" -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.