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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26952361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:10:54  来源:igfitidea点击:

Yet another "ld: symbol(s) not found for architecture x86_64" issue with boost, this time with mgiza

c++xcodeboostmakefilecmake

提问by ComputerScientist

I apologize for asking such a common question; I can't find any solution out there that works or is clear enough for me to implement. I am simply trying to install mgiza. Here is the INSTALL file:

我很抱歉问了这么一个常见的问题;我找不到任何可行或足够清晰的解决方案让我实施。我只是想安装mgiza。这是安装文件:

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

Looks easy, right? Typing in cmake .works without any apparent problems. Unfortunately, makeruns into this dreaded error ("undefined symbols ...") with boost.

看起来很容易,对吧?输入cmake .工作没有任何明显问题。不幸的是,make使用 boost 遇到了这个可怕的错误(“未定义的符号......”)。

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)

Based on other questions, it's a problem with Mavericks because it uses clang to compile c++ code, implying that the library is libc++, not libstdc++. For completeness, and so that others can reproduce my errors, I am using OS X 10.9.5, Xcode 6.1, and my boost version is 1.56 (boost was installed via homebrew).

基于其他问题,这是小牛队的问题,因为它使用clang来编译c++代码,暗示库是libc++,而不是libstdc++。为了完整性,并让其他人可以重现我的错误,我使用的是 OS X 10.9.5、Xcode 6.1,我的 boost 版本是 1.56(boost 是通过自制软件安装的)。

Now, there has to be somefix out there, right? Let's go through some of them:

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

  1. Applying the -m32 flag: not applicable because the Makefile doesn't have any "g++" in it, and it also explicitly tells me NOT to edit it, because it's a "Cmake" generated file.
  2. Not defining something in a header file: not applicable because the code should be ready to compile.
  3. Adding -stdlib=libstdc++ to linker: I am not sure how to add this to a makecommand? I tried just doing make -stdlib=libstdc++and while that seemed to avoid the errors above, it introduced some additional errors: make: *** [all] Error 2(not sure what that means).
  4. Linking to proper boost libraries: There's a comment there that says "You just need to link to the proper boost libraries ... plenty of Q/As on how to do that". Unfortunately, I don't think any of the questions that commenter linked to address my problem.
  5. Linking Qt with boost: I don't think this is applicable because I'm not using Qt, and I don't know where I'd put in a LIBS += [...] boostline.
  6. Linking a missing file: That issue seems to be more about linking when running g++but I'm using a Makefile that doesn't have g++anywhere in it.
  7. Using g++ vs gcc: I don't know how I can change which of these I use, because I'm using cmakeand make...
  8. Changing a link command: Again, I don't know how I can change the compilation from cmake/maketo gcc. (Note: from this point on, I will ignore most questions that are answered by adding something to gcc or g++.)
  9. Changing the standard c++ library: the solution involves going into Xcode and changing the libraries there. I don't think this is the correct approach and in any case I'd probably screw up something if I changed a setting in Xcode (I also have no experience with Xcode's GUI).
  10. Linking libraries in Xcode: I think this is a similar case as #9 on this list. The answer here also recommends using homebrew instead of macports for installing boost, but I already said earlier that I used homebrew for installing boost.
  11. Compile with clang: A similar issue, but how do I get cmake or make to compile with clang?
  12. From a (popular) bitcoin issue: Now thislooks interesting! A ton of people ran into my error. Unfortunately, there seems to be no consensus or easy solution. There are also a few solutions that I don't know to implement. For instance, one solution by "imbolo" there is to compile boost using a cxxflag flag, but what does that mean?
  1. 应用 -m32 标志:不适用,因为 Makefile 中没有任何“g++”,它还明确告诉我不要编辑它,因为它是“Cmake”生成的文件。
  2. 不在头文件中定义内容:不适用,因为代码应该准备好编译。
  3. 将 -stdlib=libstdc++ 添加到链接器:我不确定如何将其添加到make命令中?我尝试这样做make -stdlib=libstdc++,虽然这似乎避免了上述错误,但它引入了一些额外的错误:(make: *** [all] Error 2不确定这意味着什么)。
  4. 链接到适当的 boost 库:那里有一条评论说“你只需要链接到适当的 boost 库......关于如何做到这一点的大量问答”。不幸的是,我认为评论者链接的任何问题都无法解决我的问题。
  5. 将 Qt 与 boost 联系起来:我认为这不适用,因为我没有使用 Qt,而且我不知道该放在哪里LIBS += [...] boost
  6. 链接丢失的文件:这个问题似乎更多地与运行时的链接有关,g++但我使用的 Makefile 中没有g++任何内容。
  7. 使用 g++ vs gcc:我不知道如何更改我使用的这些,因为我正在使用cmakemake......
  8. 更改链接命令:同样,我不知道如何将编译从cmake/更改makegcc. (注意:从现在开始,我将忽略通过向 gcc 或 g++ 添加一些内容来回答的大多数问题。)
  9. 更改标准 c++ 库:解决方案涉及进入 Xcode 并更改那里的库。我不认为这是正确的方法,无论如何,如果我更改了 Xcode 中的设置,我可能会搞砸一些事情(我也没有使用 Xcode 的 GUI 的经验)。
  10. 在 Xcode 中链接库:我认为这与此列表中的 #9 类似。这里的答案还建议使用 homebrew 而不是 macports 来安装 boost,但我之前已经说过我使用 homebrew 来安装 boost。
  11. 用 clang 编译:一个类似的问题,但我如何让 cmake 或 make 用 clang 编译?
  12. 从(流行)比特币的问题:现在这个看起来很有趣!很多人都遇到了我的错误。不幸的是,似乎没有达成共识或简单的解决方案。还有一些我不知道要实施的解决方案。例如,“imbolo”的一种解决方案是使用 cxxflag 标志编译 boost,但这意味着什么?

So I'm at a little bit of a loss on how to correctly install mgiza ... I mean, the whole point of mgiza giving me cmakeand makeis so that I don'thave to worry about the messy details of compiling things, right? This isn't just an mgiza issue, though, since I've run into this problem when trying to do makeelsewhere. I understand the high-level ideas of (C)Makefiles, but not the low-level details.

所以,我在如何正确安装mgiza亏损一点点......我的意思是,mgiza整点给我cmake,并make是如此,我并不需要有关编译的事情,对繁琐的细节忧? 然而,这不仅仅是一个 mgiza 问题,因为我在尝试在make其他地方做时遇到了这个问题。我了解 (C)Makefiles 的高级思想,但不了解低级细节。

采纳答案by ComputerScientist

To address some of the concerns by the commenters: the best way to deal with this problem is to try and clear your system as much as possible and start the process from scratch.

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

Also, since this was posted, OS X 10.10 Yosemite was released, which may have fixed this problem (IIRC this problem is mostly due to 10.9 and the clang/gcc complier changes).

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