我很抱歉问了这样一个常见的问题;我找不到任何可行的或足够清晰的解决方案供我实施。我只是想安装mgiza https://github.com/moses-smt/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
看起来很容易,对吧?正在输入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)
根据其他问题,这是Mavericks的问题,因为它使用clang来编译c++代码,暗示该库是libc++,而不是libstdc++。为了完整起见,并让其他人可以重现我的错误,我使用 OS X 10.9.5、Xcode 6.1,我的 boost 版本是 1.56(boost 是通过自制程序安装的)。
现在,必须有some在那里解决,对吗?让我们来看看其中的一些:
-
应用 -m32 标志 https://stackoverflow.com/questions/9272566/gcc-ld-symbols-not-found-for-architecture-x86-64:不适用,因为 Makefile
里面没有任何“g++”,它也明确告诉我不要
编辑它,因为它是“Cmake”生成的文件。
-
未在头文件中定义某些内容 https://stackoverflow.com/questions/21966887/undefined-symbols-for-architecture-x86-64-xcode-5-issues:不适用,因为代码应该准备好编译。
-
将 -stdlib=libstdc++ 添加到链接器 https://stackoverflow.com/questions/19637164/c-linking-error-after-upgrading-to-mac-os-x-10-9-xcode-5-0-1:我不知道如何将其添加到
make
命令?我试着做make -stdlib=libstdc++
虽然这似乎避免了上述错误,但它引入了一些额外的错误:make: *** [all] Error 2
(不确定那是什么意思)。
-
链接到正确的 boost 库 https://stackoverflow.com/questions/21590507/boost-xcode-c-command-line-undefined-symbols-for-architecture-x86-64:那里有一条评论说“你只需要链接到正确的升压库......关于如何做到这一点有大量的问答”。不幸的是,我认为评论者链接的任何问题都不能解决我的问题。
-
将 Qt 与 boost 链接起来 https://stackoverflow.com/questions/25343335/boost-in-qt-installation-and-symbols-not-found-for-architectures-x86-64:我认为这不适用,因为我没有使用 Qt,而且我不知道在哪里放入
LIBS += [...] boost
line.
-
链接丢失的文件 https://stackoverflow.com/questions/21297447/ld-symbols-not-found-for-architecture-x86-64:这个问题似乎更多是关于运行时的链接
g++
但我使用的 Makefile 没有g++
其中任何地方。
-
使用 g++ 与 gcc https://stackoverflow.com/questions/23496692/how-can-i-fix-g-undefined-symbols-for-architecture-x86-64-error:我不知道如何更改我使用的其中哪一个,因为我正在使用
cmake
and make
...
-
更改链接命令 https://stackoverflow.com/questions/20202715/ld-symbols-not-found-for-architecture-x86-64-libusb:同样,我不知道如何更改编译
cmake
/make
to gcc
。 (注意:从现在开始,我将忽略大多数通过向 gcc 或 g++ 添加某些内容来回答的问题。)
-
更改标准 C++ 库 https://stackoverflow.com/questions/19821041/g-ld-symbols-not-found-for-architecture-x86-64:解决方案涉及进入 Xcode 并更改其中的库。我认为这不是正确的方法,无论如何,如果我更改 Xcode 中的设置,我可能会搞砸一些东西(我也没有使用 Xcode 的 GUI 的经验)。
-
在 Xcode 中链接库 https://stackoverflow.com/questions/13332807/cundefined-symbols-for-architecture-x86-64-mac-and-boost-library:我认为这与此列表中的#9 类似。这里的答案还建议使用homebrew而不是macports来安装boost,但是我之前已经说过我使用homebrew来安装boost。
-
使用 clang 编译 https://trac.macports.org/ticket/41588:类似的问题,但是如何让 cmake 或 make 使用 clang 进行编译?
-
来自(流行的)比特币问题 https://github.com/bitcoin/bitcoin/issues/3228: Now this看起来很有趣!很多人都遇到了我的错误。不幸的是,似乎没有达成共识或简单的解决方案。还有一些我不知道实施的解决方案。例如,“imbolo”的一种解决方案是使用 cxxflag 标志来编译 boost,但这是什么意思?
所以我对如何正确安装 mgiza 有点不知所措......我的意思是,mgiza 给我的全部意义cmake
and make
是这样我don't必须担心编译事情的混乱细节,对吗?不过,这不仅仅是一个 mgiza 问题,因为我在尝试执行此操作时遇到了这个问题make
别处。我了解 (C)Makefile 的高级思想,但不了解低级细节。