-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjusted link flags for Mac OS X #41
Conversation
First, glfw3 builds as libglfw3 by default, so we link against that. Then, we have to link a few frameworks, to get rid of missing symbols.
How has it worked fine before? |
By default GLFW does not build the dynamic libraries. And confusingly enough the library names are "libglfw.so" and "libglfw3.a". I don't have experience with Mac but right now we're only supporting the dynamic library. Can you check if it's the case with your patch? Also see #39 for a similar discussion for Linux. |
I tested it by linking against the static lib (this is IMHO more in the spirit of go).
|
Most linux distributions only ship the dynamic library. Windows binaries from glfw.org has both dynamic and static libraries. So in the name of consistency I would like to keep it to dynamic for Mac as well. Also, if we use static libraries, people who use binaries for glfw will have the burden to install all other needed libraries such as Xorg-devel in linux. To me it seems easier to link against the dynamic library but I'm willing to hear the arguments for static linking. |
Most linux distributions do ship with the (dynamic only) library as a package, so to distribute an application on Linux for an end user, one would build a package that depends on the given package, and it would be pulled in upon install. Going dynamic is really the most straightforward way under Linux. The typical approach is different on Mac OS X. As there is no (end-user oriented) package manager, apps are self-contained bundles that include their dependencies. Of course, someone downloading a self-contained app will certainly not want to download an app he expects to be self-contained to require manual installation of glfw. First, just as app bundles are preferred to standalone executable binaries, frameworks are preferred to dylibs. Either way, dylib paths are hardcoded into the binaries. The OSX linker provides a method to encode a relative path to the dylibs and frameworks dyld variable (more like a placeholder) named So, AFAIK, the static library is currently the most straightforward way under Mac OS X as soon as you think about distributing the final binary. Anyway bundling the dylib defeats the whole purpose of dynamic libraries so one might as well go static. I personally see no particular reason to try to maintain a form of symmetry at this level across both platforms, since they have their own idiosyncrasies. Still, suggestions as to how to cleanly bundle a dylib in an app bundle are otherwise welcome. |
There are other purposes of bundling a dynamic library such as end-user being able to replace it _but_ I'm OK with your approach. I've never used a Mac so I'm in no position to disagree with what you're saying. Edit: Shall we mention brew.sh in the README? Is it easy to get the glfw3 framework with it? |
Static libraries don't work with go on mac, it causes every symbol to be linked to 0x0 without generating any errors. See this bug discussion for more details: https://code.google.com/p/go/issues/detail?id=4868 The only way to run glfw with go is to use dynamic libraries. |
An example run:
Which I think is not the same issue, since it's a SIGILL, not a SIGSEGV the symbols are there with a non-0x0 address. Case in point: Note: foo.local has no trace whatsoever of any glfw. |
I swear I made it work previously, but I was building on another machine: I very recently migrated from a '09 MacBook Pro to a brand new Retina 13". So instead of trying on another machine, I tried on the same one, but:
and voilà, it works. To wit: Of note: static linking requires Go 1.1. |
Go, or the compiler used to build libglfw3 (which might just be more likely). |
Confirmed: I built libglfw3 on a C2D, copied it to my i5, rebuilt go-go/glfw3 and example.go, copied it to the clean iMac, and ran it with no issues. TL;DR: static linking works. BTW, the code.google.com issue mentioned above refers to someone trying to build go code against the static lib way before go 1.1, hence with no static library support. |
I know the google code issue is old, but it still seems to be affecting me. Here is my run:
I'm building go-gl/glfw against libglfw3.a. This seems to be identical to the issue in the google bug report. |
Let's look at this deeper then. How did you install/build go, and libglfw3? Is the issue reproducible with the go-gl/glfw3 example? Which OS, Xcode version and C compiler are you using? Did you install Apple's gcc-42 (which doesn't work anymore with recent Xcode) |
Installed go with installer package from google code. I have not installed any different versions of gcc. The current version on my system is 4.2.1. |
I replicated the bug: it is caused by the official golang installer release. There is no such problem with homebrew's built from source version (which I would recommend anyway). |
glfw3 is getting some love from homebrew in the homebrew-versions tap, which should be merged shortly. I updated the formula to build dynamically as Following the merge, installing glfw3 will be like:
Skip the |
Ok, that explains everything (what I wrote above and #47). When doing I've always used shared libraries on OS X, but I would prefer to use static if it works. I'll try that now. |
Ok, I'm having the same issue as @charliehorse55 when trying the static linking approach. go-gl/glfw3 builds successfully (an only 4 KB increase in size over the shared library version; 465 KB vs. 461 KB). But running at trivial go glfw3 program gives:
I'm on |
Yeah, upstream made naming decisions that end up being confusing as hell. I made the glfw3 homebrew formula always build as libglfw3, so that it can be installed alongside glfw2 (which builds as libglfw). In any case, glfw3 names everything as 'glfw3' in terms of files (and glfw in terms of code), except the dylib. See the homebrew-versions tap (specifically this PR) |
@lloeki How are you able to build and run statically built glfw3 go programs? |
@shurcooL did you use the official golang package (from code.google.com)? if so, it's broken, and you should give homebrew a shot. |
Edit: Never mind, I misread what you said. Yes, I used the official golang package. I'll try building Go from source then. |
To sum up:
If you want to redistribute the binaries, be sure to use:
Else it'll build with something like |
Is there a golang issue opened for their installer bug? |
There's the aforementioned issue, but its current status 'retracted' might make it invisible. I'll create a new one. Since I see this as the mist straightforward way to install go, glfw3 and g-gl/glfw3, I'd say yes, it should be in the README. |
Ok, I can finally confirm what @lloeki has been saying. I tried to install go1.1.2 from source, but because I already have Xcode 5 which breaks it, I couldn't. Instead I installed go1.2rc1 from source and I was able to successfully statically link with libglfw3.a and run a program. :D So both shared and static libraries are supported on OS X, at the very least. However, the build + run times seem to be significantly worse than when doing shared library. If this is confirmed to be true, then we should probably try to offer the option for both types of linking so the user can decide what's better for them. For instance, I would take faster build time of shared library, but stick with static for creating release binaries. But this needs to be verified first. Edit: Yeah, I think my build+run time calculation was faulty, thankfully. |
I did not notice anything particular on that front: Static:
Dynamic:
Anyway, no problem, with the consistent naming scheme we don't have to touch go-gl/glfw source code:
|
First, glfw3 builds as libglfw3 by default, so we link against that.
Then, we have to link a few frameworks, to get rid of missing symbols.
glfw3 homebrew PR pending: Homebrew/legacy-homebrew#21620
FWIW, the glfw -> glfw3 move is probably valid for Linux too, but I can't test that right now, so not included.