8

Use case: I want to use a 3rd party static library that uses libstdc++ (cannot be changed), so I have to link my app against libstdc++. Now if I want to use C++11 features in my own code, I'd have to select libc++ in Xcode and additionally link against libstdc++ to satisfy the static library.

My problem is that even though I selected libc++ in "Build settings" and added "-lstdc++" to "Other linker flags" (also tried via "Build phases > Link Binary With Libraries"), I'm getting linker errors for the latter, that is for libstdc++ functions/classes referenced by the 3rd party lib.

How can I configure the project to link against both C++ standard libraries? It should theoretically be possible since libc++ will be in its own inline namespace std::__1.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
AndiDog
  • 68,631
  • 21
  • 159
  • 205
  • 1
    Have you checked [this answer](http://stackoverflow.com/a/12546314/1921751)? It may give you a hint on how to solve your problem. Personally, I think it will be a real pain to get that working with both libstdc++ and libc++, but anything is possible! Isn't there any way you can get the source from those 3rd party static libraries and compile them using libc++? I had this problem but fortunately I had access to the source so I just recompiled everything with "-stdlib=libc++" and the linker errors were gone. – André Neves Apr 18 '13 at 14:02

1 Answers1

10

I just ran into this , and my solution was that instead of adding -lstdc++ on the other flags, that you put /usr/lib/libstdc++.dylib.

My hunch is that when xcode/clang has -std=c++ set, the older .dylib needs to be explicitly loaded.

Andriy
  • 2,767
  • 2
  • 21
  • 29
SonicBison
  • 790
  • 7
  • 21