How to resolve libstdc++.6.dylib dependency

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How to resolve libstdc++.6.dylib dependency

Andreas Falkenhahn
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?

--
Best regards,
 Andreas Falkenhahn                          mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to resolve libstdc++.6.dylib dependency

pagani laurent via macports-users
I don’t know much about these libraries but there exists a libstdc++.a library. No idea if it is different in content from the .6 one but if not, you could do a static link so that you don’t need any library for the users to run your program. Not sure it helps. The other solution is to try to find or build the libstdc++.6.a library yourself and perform a static link.

Laurent

Le 24 mars 2018 à 13:35, Andreas Falkenhahn <[hidden email]> a écrit :

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?

--
Best regards,
Andreas Falkenhahn                          [hidden email]


"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème" (devise Shadok)

Reply | Threaded
Open this post in threaded view
|

Re: How to resolve libstdc++.6.dylib dependency

Mojca Miklavec-2
In reply to this post by Andreas Falkenhahn
On 24 March 2018 at 13: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?

You need to compile with ABI 4 compatibility (add
"-D_GLIBCXX_USE_CXX11_ABI=0" to CXXFLAGS) and then relink them to
/usr/lib/libstdc++.6.dylib with install_name_tool.

The first step might soon no longer be required (see
https://github.com/macports/macports-ports/pull/1469), but you'll
probably need to keep running install_name_tool on the resulting
libraries/binaries, I assume that your binaries link against
/opt/local/lib/libstdc++.6.dylib rather than
/usr/lib/libstdc++.*.dylib

Mojca
Reply | Threaded
Open this post in threaded view
|

Re: How to resolve libstdc++.6.dylib dependency

Ken Cunningham
In reply to this post by Andreas Falkenhahn
Cameron Kaiser builds and distributes TenFourFox which is a c++11 app built with gcc48 against a new libstdc++. 

He has worked a lot of this out.

His instructions are here <https://github.com/classilla/tenfourfox/wiki/HowToBuildFPR#distributing-the-executable>, and there's a script in the repo that automates a lot of it.

Best, Ken

On Mar 24, 2018, at 06:35, Andreas Falkenhahn <[hidden email]> 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?

--
Best regards,
Andreas Falkenhahn                          [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to resolve libstdc++.6.dylib dependency

Andreas Falkenhahn
In reply to this post by Mojca Miklavec-2
On 24.03.2018 at 14:07 Mojca Miklavec wrote:

> On 24 March 2018 at 13: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?

> You need to compile with ABI 4 compatibility (add
> "-D_GLIBCXX_USE_CXX11_ABI=0" to CXXFLAGS) and then relink them to
> /usr/lib/libstdc++.6.dylib with install_name_tool.

> The first step might soon no longer be required (see
> https://github.com/macports/macports-ports/pull/1469), but you'll
> probably need to keep running install_name_tool on the resulting
> libraries/binaries, I assume that your binaries link against
> /opt/local/lib/libstdc++.6.dylib rather than
> /usr/lib/libstdc++.*.dylib

Yes, it does. Unfortunately, compiling with -D_GLIBCXX_USE_CXX11_ABI=0 and
then changing /opt/local/lib/libstdc++.6.dylib to /usr/lib/libstdc++.6.dylib
using install_name_tool doesn't work. It still can't find some symbols.
Here's the error I get when trying to dlopen() my project:

dyld: lazy symbol binding failed: Symbol not found: __ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_i
  Referenced from: test.dylib
  Expected in: /usr/lib/libstdc++.6.dylib

dyld: Symbol not found: __ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_i
  Referenced from: test.dylib
  Expected in: /usr/lib/libstdc++.6.dylib

--
Best regards,
 Andreas Falkenhahn                            mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to resolve libstdc++.6.dylib dependency

Andreas Falkenhahn
In reply to this post by Ken Cunningham
On 24.03.2018 at 16:07 Ken Cunningham wrote:

> Cameron Kaiser builds and distributes TenFourFox which is a c++11
> app built with gcc48 against a new libstdc++.
> He has worked a lot of this out.
> His instructions are here
> <https://github.com/classilla/tenfourfox/wiki/HowToBuildFPR#distributing-the-executable>,
> and there's a script in the repo that automates a lot of it.

Yeah, so basically he's just shipping the new link libs with the
distribution which is of course something I wanted to avoid.

Well, maybe I should just tell my users that they need to
install gcc6 from Mac Ports if they wish to use the program.
People who are still on PPC Macs are geeks anyway ;)

--
Best regards,
 Andreas Falkenhahn                            mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to resolve libstdc++.6.dylib dependency

Mojca Miklavec-2
On 24 March 2018 at 16:40, Andreas Falkenhahn wrote:

> On 24.03.2018 at 16:07 Ken Cunningham wrote:
>
>> Cameron Kaiser builds and distributes TenFourFox which is a c++11
>> app built with gcc48 against a new libstdc++.
>> He has worked a lot of this out.
>> His instructions are here
>> <https://github.com/classilla/tenfourfox/wiki/HowToBuildFPR#distributing-the-executable>,
>> and there's a script in the repo that automates a lot of it.
>
> Yeah, so basically he's just shipping the new link libs with the
> distribution which is of course something I wanted to avoid.
>
> Well, maybe I should just tell my users that they need to
> install gcc6 from Mac Ports if they wish to use the program.
> People who are still on PPC Macs are geeks anyway ;)

In that case, depending on usability, you could probably provide a
MacPorts package as well.

Sorry about the wrong advice about stdlib. Maybe that technique just
ensures the compatibility, so that the libraries linked against each
other won't clash and crash if one is linking against the system lib
and the other against the one from gcc7.

Mojca
Reply | Threaded
Open this post in threaded view
|

Re: How to resolve libstdc++.6.dylib dependency

Andreas Falkenhahn
On 24.03.2018 at 17:34 Mojca Miklavec wrote:

> Sorry about the wrong advice about stdlib.

No worries, I've had another idea. I can just link statically
against libgcc and libstdc++, like so:

-static-libgcc -static-libstdc++

This increases the executable size by about 1 MB but the
resulting executable works like a charm on a naked 10.5
system without any Mac Ports stuff... very nice!

--
Best regards,
 Andreas Falkenhahn                            mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to resolve libstdc++.6.dylib dependency

Ryan Schmidt-24
In reply to this post by Andreas Falkenhahn

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.

Reply | Threaded
Open this post in threaded view
|

Re: How to resolve libstdc++.6.dylib dependency

Ken Cunningham
In reply to this post by Andreas Falkenhahn
that's probably the simplest solution for simple executables with no complicated web of supporting libraries.

I wonder if the same thing could work for Mojca's libc++ issues with her binaries?

Ken



On 2018-03-24, at 11:20 AM, Andreas Falkenhahn wrote:

> On 24.03.2018 at 17:34 Mojca Miklavec wrote:
>
>> Sorry about the wrong advice about stdlib.
>
> No worries, I've had another idea. I can just link statically
> against libgcc and libstdc++, like so:
>
> -static-libgcc -static-libstdc++
>
> This increases the executable size by about 1 MB but the
> resulting executable works like a charm on a naked 10.5
> system without any Mac Ports stuff... very nice!
>
> --
> Best regards,
> Andreas Falkenhahn                            mailto:[hidden email]
>