升级到Mac OS X 10.9 / Xcode 5.0.1后出现C ++链接错误 [英] C++ linking error after upgrading to Mac OS X 10.9 / Xcode 5.0.1

查看:117
本文介绍了升级到Mac OS X 10.9 / Xcode 5.0.1后出现C ++链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到Mac OS X 10.9 / Xcode 5.0.1后,创建共享库(.dylib)的命令行失败,出现了多个未定义的符号。

  clang ++ -dynamiclib -install_name test.dylib * .o -o test.dylib 
架构x86_64的未定义符号:
std :: allocator< char> ,引用自:
_main in test.o
std :: allocator< char> ::〜allocator(),引用自:
_main in test.o
std :: ostream :: operator<<(std :: ostream&(*)(std :: ostream&)),引用自:
_main in test.o
std :: basic_string< char,std :: char_traits< char>,std :: allocator< char>> :: basic_string(char const *,std :: allocator< char> const&),引用自:
_main test.o
std :: basic_string< char,std :: char_traits< char>,std :: allocator< char>> ::〜basic_string(),引用自:
_main .o
std :: ios_base :: Init :: Init(),引用自:
___cxx_global_var_init in test.o
std :: ios_base :: Init ::〜Init ),引用自:
___cxx_global_var_init in test.o
std :: cout,引用自:
_main in test.o
std :: basic_ostream& std :: char_traits< char> >& std :: endl< char,std :: char_traits< char> >(std :: basic_ostream< char,std :: char_traits< char>>&),引用自:
_main in test.o
std :: basic_ostream& :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> ,引用自:
_main in test.o
ld:未找到用于架构x86_64的符号


解决方案

答案是: http://mathematica.stackexchange.com/questions/34692/mathlink-linking-error-after-os-x-10-9-mavericks-upgrade


在OS X上有两个标准C ++库的实现:libstdc ++和libc ++,它们不是二进制兼容的,libMLi3需要libstdc ++。 / p>

在10.8和早期版本中,默认选择libstdc ++,10.9为了确保与libMLi3兼容,我们需要手动选择libstdc ++。 b
$ b

为此,请将-stdlib = libstdc ++添加到链接命令中。


使用Libc ++编译未定义的引用






编辑:经过一番调查后,似乎-mmacosx-version-min的默认libstd。如果min版本< 10.9,则默认的libstd等于libstdc ++,否则为libc ++。长期解决方案显然是使用-stdlib = libc ++


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

解决方案

The answer is there: http://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++"

这篇关于升级到Mac OS X 10.9 / Xcode 5.0.1后出现C ++链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆