PDA

View Full Version : [Resolved] Possible to release C++11 (+ library) applications for OSX 10.6?




printz
May 21, 2013, 09:42 AM
If I'm in Xcode 4 and set the compiler to use the C++11 standard libraries, I get a warning that my program will only work on OSX 10.7 and later.

On OSX 10.6, I'm able to install GCC 4.8, via MacPorts, to get C++11 support, complete with its associated libstdc++. I can build such programs from a Makefile. But are such programs portable, or do they require MacPorts and GCC 4.8 installed on user's computers? I wonder if I can package libstdc++ (as installed by MacPorts) with my program, inside the app bundle. Any idea which file I should take? There are several libstdc++ dylib files in my /opt/local/lib folder, am I supposed to bundle one of them?



superriku11
May 23, 2013, 01:25 AM
If I'm in Xcode 4 and set the compiler to use the C++11 standard libraries, I get a warning that my program will only work on OSX 10.7 and later.

On OSX 10.6, I'm able to install GCC 4.8, via MacPorts, to get C++11 support, complete with its associated libstdc++. I can build such programs from a Makefile. But are such programs portable, or do they require MacPorts and GCC 4.8 installed on user's computers? I wonder if I can package libstdc++ (as installed by MacPorts) with my program, inside the app bundle. Any idea which file I should take? There are several libstdc++ dylib files in my /opt/local/lib folder, am I supposed to bundle one of them?

C++ compiles to regular machine code so presumably it should work. It may rely on libraries put in place by your MacPorts installation(s) however, so the only way to know is to try.

Cactus Dan
May 24, 2013, 11:18 AM
Howdy,

Do you absolutely need C++11? I mean if you're worried about backward compatibility can you still make it work by doing your development in 10.6?

Or, can you create wrapper function calls that check for the Mac OSX version, and within the wrapper function make the appropriate call to the C++ functions?

Or, can you just compile separate versions, using preprocessor defines to determine which Mac OS you're compiling and have both the 10.7 code and the 10.6 code in the same source?

That last method I use quite frequently to keep my Cinema 4D plugins backward compatible with many versions of the application's API.

Adios,
Cactus Dan

printz
May 25, 2013, 09:54 AM
It's not my code, so I don't have that level of control. All I do is port it to OSX.

Madd the Sane
May 26, 2013, 02:21 PM
If you must have C++11 and 10.6 support, find a way to link the C++11 library statically to your app.

printz
May 26, 2013, 04:00 PM
And which is that? libc++? libstdc++? libc++abi?

Can I use that Terminal command whose name escapes me now (it has two letters IIRC) that lists the dependencies of the executable?

chown33
May 26, 2013, 04:12 PM
And which is that? libc++? libstdc++? libc++abi?

Can I use that Terminal command whose name escapes me now (it has two letters IIRC) that lists the dependencies of the executable?

otool ? nm ?

You should read their man pages to find out which one. Then try them on your executable, with various options as available, and see what you get. I suspect 'otool -L' will be the most revealing.

If 'otool -L' tells you what you need to know, then here's a thread (http://forums.macrumors.com/showthread.php?t=1348501) about changing the install-name of dylibs.

Madd the Sane
May 26, 2013, 06:00 PM
You most likely will have to build the C++11 library as a static and then link to it.

You most likely will be using a version of GCC, so the library would be libstdc++. I don't know if Clang's libc++ will build on 10.6, because I don't know if the dependent libc++abi will build.

printz
May 27, 2013, 10:09 AM
Looks like I can download Clang binary from its website. I can also download libc++ and libc++abi from MacPorts.

Looking over the Internet, a common suggestion on this issue was to supply libc++ and libc++abi with my program.

I wonder: how do I tell the independent (non-Apple) Clang to link with a portable (relative to executable directory) libc++?
EDIT: Found this too http://libcxx.llvm.org/. It has both libc++ and how to use it instead of system's… Now to find out how to make it either statically linked, or portable.

Currently MacPorts is downloading and compiling libc++ and libc++abi. I wonder if it will also create .a files.

Big problem is that I just cannot expect users to wait hours for something to install, as it is via MacPorts/Homebrew/Fink in general.

printz
May 31, 2013, 07:56 AM
I managed to do it by downloading libc++ and libc++abi from libcxx.llvm.org and libcxxabi.llvm.org. I also needed clang from clang.llvm.org. On the libraries, I edited the buildit scripts to produce dylibs whose install_name are @loader_path/<lib name> (where you substitute <lib name> for the file name). I had to build libc++abi first, this way, then libc++. I also had to make sure everything uses the downloaded clang compiler, not the OSX built-in one.