【发布时间】:2014-07-02 21:57:21
【问题描述】:
关于这个主题有很多线程,但我尝试了一些解决方案,但似乎没有任何效果。
如果我安装 boost :
brew install booost --c++11
并尝试编译以下程序 tut1.cpp:
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: tut1 path\n";
return 1;
}
std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
return 0;
}
使用
clang -I /usr/local/Cellar/boost/1.55.0_1/include/ -L /usr/local/Cellar/boost/1.55.0_1/lib/ tut1.cpp
它失败了:
Undefined symbols for architecture x86_64:
"boost::filesystem::path::codecvt()", referenced from:
boost::filesystem::path::path<char*>(char* const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<char*>::type>, void>::type*) in tut1-6a2087.o
...
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
链接似乎是个问题,因为如果我调用 -c 选项,就会创建目标文件。
你知道到底发生了什么吗?
【问题讨论】:
-
也尝试链接相关库,例如
-lboost_filesystem。见stackoverflow.com/questions/13467072/…