7

In OSX 10.9 the default -stdlib option for clang++ is libc++, so that's what Macport uses when building packages. Is there any way to tell Macports to use libstdc++ instead?

In particular I would like to build OpenCV through Macports so it's using libstdc++, but I imagine I'll run into a need to do so for other packages as well

Puchatek
  • 1,477
  • 3
  • 15
  • 33
  • Why would you like to do this? – rubenvb Feb 04 '14 at 08:00
  • Because otherwise my builds break. My main compiler is g++ and it's quite likely other libs I use rely on libstdc++ too. In short I have build fine the same code on OSX 10.8 and the only difference I see is that OpenCV on my 10.9 machine relies on libc++, while on 10.8 machine on libstdc++. – Puchatek Feb 04 '14 at 08:01
  • why does your build break? It might be a problem in any of your code, libstdc++ or libc++. – rubenvb Feb 04 '14 at 09:39
  • It might of course. Here's what I know - the same code builds on osx 10.8 but breaks on linking with undefined symbols on 10.9. Library that fails to link is OpenCV, but I know it is present, lib path set, etc. Looking through what OpenCV lib links to, the only difference between two machines is that one that on 10.8 OpenCV links to libstdc++ and on 10.9 to libc++. Also the errors right after undefined OpenCV symbols are all about std::strings family, which is the common symptom of of libstdc++ and libc++ clash. – Puchatek Feb 06 '14 at 02:02
  • you need to recompile OpenCV with libc++ of course. They're not binary compatible... – rubenvb Feb 06 '14 at 08:11
  • Read the macports development list - in practice you need to stick to one std library and all the macports is built with clang and libc++ so much easier for you to use these. – mmmmmm Feb 26 '14 at 11:36

2 Answers2

4

The option is simply: -stdlib=libstdc++

If you need finer control over the build process for various ports, you can always set variables like:
CXX = "clang -std=c++11 -stdlib=libc++, CXXFLAGS = "-Wall -O2 -march=core2", etc.

And build <port> from source:

sudo port -s install <port> -universal \  
configure.cc="${CC}" configure.cxx="${CXX}" \  
configure.cflags="${CFLAGS}" configure.cxxflags="${CXXFLAGS}"

The other alternative, is to install the gcc48 (or above) port, and use it as the compiler. Don't use the old gcc-4.2.1 installed with older versions of Xcode. It's rubbish.

ykaganovich
  • 14,736
  • 8
  • 59
  • 96
Brett Hale
  • 21,653
  • 2
  • 61
  • 90
  • 2
    Strange, Macports accepts those options, but doesn't honour them. I removed OpenCV library, build it passing CXX flag that with `-stdlib=libstdc++` and still built library was linking to libc++. – Puchatek Feb 06 '14 at 01:56
2

One way to accomplish this appears to be to build opencv from source, and use the configure.cxx_stdlib variable to specify libstdc++ as your C++ runtime.

Try out the following:

sudo port install -s opencv configure.cxx_stdlib="libstdc++"
Bill Agee
  • 3,606
  • 20
  • 17