Getting a universal static libstdc++ library through MacPorts

Ryan Schmidt ryandesign at macports.org
Thu Mar 21 14:55:19 PDT 2013


On Mar 21, 2013, at 16:29, Alex Reynolds wrote:

> I publish some open-source software to a scientific community that runs Linux and OS X. 
> 
> The OS X builds I am distributing are fat (universal) binaries created with GCC 4.7.2 (universal) obtained through MacPorts.
> 
> I am getting reports from some end users of errors of the following kind:
> 
> ------
> dyld: lazy symbol binding failed: Symbol not found: __ZNSt8__detail15_List_node_base7_M_hookEPS0_
> Referenced from: /usr/local/bin/myBinary
> Expected in: /usr/lib/libstdc++.6.dylib
> ------
> 
> Even when compiling my binaries with the -static-libstdc++ flag, it looks like the dynamic C++ and C libraries are linked into the binary:
> 
> ------
> $ otool -L /usr/local/bin/myBinary
> /usr/local/bin/myBinary:
>        /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
>        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
>        /opt/local/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.17.0)
>        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1669.0.0)
>        /opt/local/lib/gcc47/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
>        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
> ------
> 
> It also looks like there is no /opt/local/lib/libstdc++.6.a installed by MacPorts. So that may explain why the -static-libstdc++ flag fails to work.
> 
> Perhaps one way to fix this would be to suggest that end users install GCC 4.7.2 (universal) through MacPorts, in order to get a copy of the dynamic library into /opt/local/lib, and then they would use sudo to make a symbolic link from the library in /opt/local/lib to /usr/lib.
> 
> I'd like to avoid this solution, since they would have to have root access and some skill with the command-line, compiling applications, and making symbolic links that may break between OS X system updates and upgrades. 
> 
> Also, the main point of distributing pre-built binaries is also to save end users the hassle of doing all this error-prone work and system customization.
> 
> Is there a way to get a static libstc++ library for the GCC 4.7.2 (universal) port through MacPorts, which I can statically link into my binary? 
> 
> My hope then is that end users will not have to install MacPorts and GCC 4.7.2 (universal) before running my binaries, and that they will be able to run my binaries without errors (at least, those errors that appear to be related to missing libraries).
> 
> Failing that, what is the process for getting a local copy of the port — before MacPorts builds it — to be able to modify how the universal GCC build is built, to somehow get the static library built?
> 
> I'm not too familiar with how MacPorts does its magic. I have tried looking through /opt/local, but I'm not sure where the files are kept that built my installation of GCC 4.7.2 (universal). Is there a Portfile (?) that I would modify? How would I modify it before MacPorts completes its build, and where is it kept? If my question is stupid or too broad, I apologize in advance for wasting others' time. I appreciate any help with this.

If you are distributing pre-built binaries, then you should include all necessary parts in that binary distribution. As it stands now, in the absence of a static libstdc++, gcc47 appears to be one of those necessary parts for you, so you should be including it in your distribution. Assuming your software is installed using a MacPorts portfile, you would simply use the "port mpkg" command to create a binary distribution including all dependencies. If you do this, you should ensure that your MacPorts is compiled with a different prefix unique to your software (instead of /opt/local).

But based on the very basic questions you've asked about portfiles, it sounds like you're not using MacPorts to install your software. If you wish to learn how to write portfiles, our guide at http://guide.macports.org has lots of information, and you can ask on the macports-dev mailing list if you have questions. The location of a port file is printed by the command e.g. "port file gcc47". You can edit it manually in your favorite editor (after giving it root permission) or use e.g. "port edit gcc47" if you have your EDITOR environment variable set up suitably.




More information about the macports-users mailing list