13

How can I tell if a library has been built with libc++ or libstdc++ on mac?

I have been using otool -L, but this does not seem to show it (mac has no ldd)

If i have library X, I want to know if I have to rebuild it as I move from GCC to clang. I have built a number of libraries with GCC, mac libraries are generally built with clang AFAIK.

user1460739
  • 319
  • 2
  • 8

2 Answers2

8

Static library: nm -a helloworld.a | grep __1

If you see lines containing __1, e.g. __121__basic_string, then the library was compiled with libc++. However if none of the function signatures used C++ Standard Library types, then this may not work.

Dynamic library: otool -L helloworld

Look for dependency on libc++ or libstdc++ dylib.

Peter Tseng
  • 13,613
  • 4
  • 67
  • 57
3

For dynamic libraries, otool -L would show libstdc++ if it were built against that library (i.e. if it were C++).

For static libraries, the question doesn't make sense. Static libraries aren't built against other libraries.

And you should not have to rebuild anything just because you're changing compilers. There's just the one, system-wide C++ library and it has a stable ABI.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Hmm - your comment on ABI does not seem correct regarding libc++ v libstdc++ - http://stackoverflow.com/a/8457799/1460739 – user1460739 Jun 16 '12 at 15:32
  • The issue is less the compiler change, more the standard library change. – user1460739 Jun 16 '12 at 15:33
  • 1
    That other question was about somebody specifically compiling a program using a specified C++ library but linking against a library not compiled against that same C++ library. If you just let the compiler do its thing without overriding it, you get the system stdc++ library for everything and it works. If you override it, you have to override it the same way for everything. – Ken Thomases Jun 16 '12 at 15:44