C++ 使用boost::filesystem链接但不使用gcc的程序
我有一个使用C++ 使用boost::filesystem链接但不使用gcc的程序,c++,linker,boost-filesystem,C++,Linker,Boost Filesystem,我有一个使用boost::filesystem的非常简单的程序,它取自图书馆的教程 // fs_example.cpp #include <boost/filesystem.hpp> #include <iostream> using namespace boost::filesystem; int main() { path p = current_path(); directory_iterator it{p}; while (it != direct
boost::filesystem
的非常简单的程序,它取自图书馆的教程
// fs_example.cpp
#include <boost/filesystem.hpp>
#include <iostream>
using namespace boost::filesystem;
int main() {
path p = current_path();
directory_iterator it{p};
while (it != directory_iterator()) {
std::cout << *it++ << '\n';
}
}
使用env CXX=clang++./build.sh
,程序编译并链接
$ env CXX=clang++ ./build.sh
$ ls
build.sh* fs_example* fs_example.cpp
使用env CXX=g++./build.sh
,程序无法编译
$ env CXX=g++ ./build.sh
/tmp/ccFcZ3W6.o: In function `__static_initialization_and_destruction_0(int, int)':
fs_example.cpp:(.text+0x1c1): undefined reference to `boost::system::generic_category()'
...
collect2: error: ld returned 1 exit status
为什么GCC会产生链接时间错误,而Clang不会?我如何诊断链接器为什么即使提供了参数,也无法在GCC路径中的
boost::system
中找到符号?您应该假设“一次链接”,这意味着较低级别的boost\u系统
必须出现在较高级别的boost\u文件系统之后“一次链接”意味着较低级别的boost\u系统
必须出现在较高级别的boost\u文件系统
之后。请注意,它是-std=c++14
而不是-std=c++14
。请注意它是-std=c++14
而不是-std=c++14
。
$ env CXX=g++ ./build.sh
/tmp/ccFcZ3W6.o: In function `__static_initialization_and_destruction_0(int, int)':
fs_example.cpp:(.text+0x1c1): undefined reference to `boost::system::generic_category()'
...
collect2: error: ld returned 1 exit status