【问题标题】:Having trouble compiling boost filesystem's tutorial file编译 boost 文件系统的教程文件时遇到问题
【发布时间】:2012-09-18 01:11:35
【问题描述】:

我正在尝试从 boost::filesystem 编译 this 教程文件。

我正在使用这个命令:

clang++ -std=c++11 -stdlib=libc++ tut3.cpp -L/usr/local/lib -lboost_filesystem-mt -lboost_system-mt

但是,我得到:

Undefined symbols for architecture x86_64:
  "boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::codecvt<wchar_t, char, __mbstate_t> const&)", referenced from:
      boost::filesystem::path::path<boost::filesystem::directory_entry>(boost::filesystem::directory_entry const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<boost::filesystem::directory_entry>::type>, void>::type*) in tut3-FljaLL.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我正在使用 Mountain Lion 中包含的 clang,并且使用 brew install --with-mpi --use-clang 安装了 boost。 (mpich2 也安装了--use-clang)。

详细链接器输出:

Apple clang version 4.0 (tags/Apple/clang-421.0.57) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.1.0
Thread model: posix
 "/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name tut3.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 133.3 -v -resource-dir /usr/bin/../lib/clang/4.0 -fmodule-cache-path /var/folders/nb/qkspw0z92f506gbjq9gb505r0000gn/T/clang-module-cache -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/spott/Documents/Code/ebss/bin -ferror-limit 19 -fmessage-length 272 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/nb/qkspw0z92f506gbjq9gb505r0000gn/T/tut3-9Q4qRh.o -x c++ tut3.cpp
clang -cc1 version 4.0 based upon LLVM 3.1svn default target x86_64-apple-darwin12.1.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /usr/bin/../lib/c++/v1
 /usr/local/include
 /usr/bin/../lib/clang/4.0/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o a.out -L/usr/local/lib/ /var/folders/nb/qkspw0z92f506gbjq9gb505r0000gn/T/tut3-9Q4qRh.o -lboost_filesystem-mt -lboost_system-mt -lc++ -lSystem /usr/bin/../lib/clang/4.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::codecvt<wchar_t, char, __mbstate_t> const&)", referenced from:
  boost::filesystem::path::path<boost::filesystem::directory_entry>(boost::filesystem::directory_entry const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<boost::filesystem::directory_entry>::type>, void>::type*) in tut3-9Q4qRh.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

老实说,我不确定问题是什么,有什么想法吗?

【问题讨论】:

  • 您是否确认您尝试链接的库确实存在于 /usr/local/lib 中?
  • 另外,发布详细的链接器输出,它可能会有所帮助。
  • 我回家后会发布详细的链接器输出,但我可以肯定的是,这些库确实存在于那个位置。

标签: c++ boost linker clang homebrew


【解决方案1】:

刚刚在 MacOS 上使用文件系统时遇到了同样的问题。

如果不使用以下选项编译 boost,则无法通过:

/b2 --build-dir=../boost_libs toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" 阶段 --with-filesystem

顺便说一句,这篇文章很有用:here

【讨论】:

  • 你知道传递给自制的'brew'命令以启用这些编译标志的标志吗?还是我必须手动编辑 boost.rb?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多