另一个"ld:符号未找到架构x86_64"的问题与boost,这次与mgiza

Com*_*ist 14 c++ xcode boost makefile cmake

我为提出这样一个共同的问题而道歉; 我找不到任何有效或足够清晰的解决方案供我实施.我只是想安装mgiza.这是INSTALL文件:

cmake .
make
make install

If you want to install to a custom location, add the following flag when you run cmake:
-DCMAKE_INSTALL_PREFIX=/path/to/custom/location

NOTE: Boost Version 1.48 has problem with the code, you can use either 1.46 or 1.50+. Unfortunately 1.48 is shipped with Ubuntu 12.04 LTS, you can either download and compile libboost 1.50+ from their website, or just do this:
sudo apt-get install libboost1.46-all-dev
Run Code Online (Sandbox Code Playgroud)

看起来很简单吧?打字cmake .工作没有任何明显的问题.不幸的是,make遇到了这个可怕的错误("未定义的符号......").

1 warning generated.
Linking CXX executable ../bin/d4norm
Undefined symbols for architecture x86_64:
  "std::string::_Rep::_M_destroy(std::allocator<char> const&)", referenced from:
      boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
  "std::string::_Rep::_S_empty_rep_storage", referenced from:
      boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
  "std::string::assign(char const*, unsigned long)", referenced from:
      boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
      boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)", referenced from:
      boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
      boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

基于其他问题,这是Mavericks的问题,因为它使用clang来编译c ++代码,这意味着库是libc ++,而不是libstdc ++.为了完整性,以及其他人可以重现我的错误,我使用OS X 10.9.5,Xcode 6.1,我的升级版本是1.56(通过自制软件安装了boost).

现在,必须有一些修复,对吧?让我们来看看其中一些:

  1. 应用-m32标志:不适用,因为Makefile中没有任何"g ++",它也明确告诉我不要编辑它,因为它是一个"Cmake"生成的文件.
  2. 没有在头文件中定义某些东西:不适用,因为代码应该可以编译了.
  3. 将-stdlib = libstdc ++添加到链接器:我不确定如何将其添加到make命令中?我尝试过这样做make -stdlib=libstdc++,虽然这似乎避免了上述错误,但它引入了一些额外的错误:( make: *** [all] Error 2不确定这意味着什么).
  4. 链接到适当的boost库:那里有一个评论说"你只需要链接到适当的boost库......大量的Q/As如何做到这一点".不幸的是,我不认为评论者提出的任何问题可以解决我的问题.
  5. 将Qt与boost联系起来:我不认为这是适用的,因为我没有使用Qt,我不知道我在哪里LIBS += [...] boost排队.
  6. 链接丢失的文件:这个问题似乎更多的是关于运行时的链接,g++但我使用的是没有g++任何地方的Makefile .
  7. 使用g ++ vs gcc:我不知道如何改变我使用的这些,因为我正在使用cmakemake......
  8. 更改链接命令:再说一遍,我不知道我怎么能编译从改变cmake/ makegcc.(注意:从这一点开始,我将忽略通过向gcc或g ++添加内容而回答的大多数问题.)
  9. 更改标准c ++库:解决方案涉及进入Xcode并在那里更改库.我不认为这是正确的方法,在任何情况下,如果我在Xcode中更改了一个设置,我可能会搞砸一些东西(我也没有使用Xcode的GUI的经验).
  10. 链接Xcode中的库:我认为这与此列表中的#9类似.这里的答案还建议使用自制软件而不是macports来安装boost,但我之前已经说过我用homebrew来安装boost.
  11. 用clang编译:一个类似的问题,但是如何使用clang编译cmake或make?
  12. 从(流行的)比特币问题:现在看起来很有趣!很多人遇到了我的错误.不幸的是,似乎没有达成共识或简单的解决方案.还有一些我不知道要实现的解决方案.例如,"imbolo"的一个解决方案是使用cxxflag标志编译boost,但这意味着什么?

所以我对如何正确安装mgiza感到有点失落......我的意思是,mgiza的全部意义在于给予我,cmake并且make不必担心编译事物的混乱细节,对吧?然而,这不仅仅是一个mgiza问题,因为我在尝试make其他地方时遇到了这个问题.我理解(C)Makefiles的高级思想,但不是低级细节.

Com*_*ist 2

针对评论者的一些担忧:处理此问题的最佳方法是尝试尽可能地清理您的系统并从头开始该过程。

另外,自从这篇文章发布以来,OS X 10.10 Yosemite 已经发布,这可能已经解决了这个问题(IIRC 这个问题主要是由于 10.9 和 clang/gcc 编译器的更改)。