Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

linker - C++ linking error after upgrading to Mac OS X 10.9 / Xcode 5.0.1

After upgrading to Mac OS X 10.9 / Xcode 5.0.1, command lines to create a shared library (.dylib) failed with several undefined symbols.

clang++ -dynamiclib -install_name test.dylib *.o -o test.dylib
Undefined symbols for architecture x86_64:
  "std::allocator<char>::allocator()", referenced from:
      _main in test.o
  "std::allocator<char>::~allocator()", referenced from:
      _main in test.o
  "std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
      _main in test.o
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
      _main in test.o
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
      _main in test.o
  "std::ios_base::Init::Init()", referenced from:
      ___cxx_global_var_init in test.o
  "std::ios_base::Init::~Init()", referenced from:
      ___cxx_global_var_init in test.o
  "std::cout", referenced from:
      _main in test.o
  "std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
      _main in test.o
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<<<char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      _main in test.o
ld: symbol(s) not found for architecture x86_64
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The answer is there: https://mathematica.stackexchange.com/questions/34692/mathlink-linking-error-after-os-x-10-9-mavericks-upgrade

There are two implementations of the standard C++ library available on OS X: libstdc++ and libc++. They are not binary compatible and libMLi3 requires libstdc++.

On 10.8 and earlier libstdc++ is chosen by default, on 10.9 libc++ is chosen by default. To ensure compatibility with libMLi3, we need to choose libstdc++ manually.

To do this, add -stdlib=libstdc++ to the linking command.

Related post: Compiling with Clang using Libc++ undefined references


Edit: After some investigations it seems there is a link between the -mmacosx-version-min and the choice of the default libstd. If min version < 10.9, then the default libstd is equal to libstdc++, else to libc++. The long term solution is clearly to use -stdlib=libc++


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...