How to resolve libstdc++.6.dylib dependency
Ryan Schmidt
ryandesign at macports.org
Sun Mar 25 04:38:06 UTC 2018
On Mar 24, 2018, at 07:35, Andreas Falkenhahn wrote:
> When I compile my C++11 project on a 10.5 PPC system using gcc6 and try to run it on another 10.5 PPC system that doesn't have gcc6 installed, I get an error that a symbol cannot be imported from /usr/lib/libstdc++.6.dylib. I guess this is because the libstdc++.6.dylib that is shipped with 10.5 doesn't contain those new features required by C++11 programs.
>
> So what is the recommended way of getting the libstdc++.6.dylib required by my program onto a user system? Of course I wouldn't like to bother users to install gcc6 from Mac Ports just to be able to run my program. Is there an easier way? Is the latest libstdc++ available as its own package in Mac Ports maybe or what is the suggested way of dealing with this?
/usr/lib/libstdc++.6.dylib does not support C++11, on any version of macOS. It is based on GCC 4.2.1.
MacPorts provides an updated libstdc++.6.dylib which does support C++11. It is based on GCC 7.3.0 at present and is updated when newer stable versions of GCC are released. It is in the libgcc port.
You must either statically link with a newer libstdc++.6.dylib, such as ours, which supports C++11, or you must bundle it and dynamically link with it. Dynamic linking is usually preferred on macOS.
If all of your C++ libraries and programs link with a newer C++11 copy of libstdc++.6.dylib, then that's fine. If some of your C++ libraries and programs link with a newer C++11 copy of libstdc++.6.dylib and other libraries and programs link with the non-C++11-supporting OS-provided copy of libstdc++.6.dylib, and you want to share information between them, then you must use -D_GLIBCXX_USE_CXX11_ABI=0 to build the parts that use the newer C++11-capable libstdc++.6.dylib, as Mojca said.
Needless to say, this is an advanced topic. It's simpler to link with /usr/lib/libc++.1.dylib, which supports C++11, but is only available on OS X 10.7 and newer.
More information about the macports-users
mailing list