C++ c++;boost::filesystem未定义对`boost::filesystem3::path::root_name()const';

C++ c++;boost::filesystem未定义对`boost::filesystem3::path::root_name()const';,c++,boost,g++,C++,Boost,G++,在尝试编译利用boost::filesystem库的代码时,我经常遇到错误。我不理解我得到的任何编译器输出。以下是我的代码复制自: 我做错了什么?您必须链接到-lboost\u文件系统-lboost\u系统。Boost文件系统不是一个只包含头的库;相反,它取决于已编译的组件。下次,请突出显示您的代码并点击Ctrl+K或使用{}编辑器中的按钮。标记德语已作为的一部分删除。您的意思是我需要将我的命令行更改为:g++-lboost_filesystem-o pr3 pr3.cppI在我的命令行末尾添加

在尝试编译利用boost::filesystem库的代码时,我经常遇到错误。我不理解我得到的任何编译器输出。以下是我的代码复制自:


我做错了什么?

您必须链接到
-lboost\u文件系统-lboost\u系统
。Boost文件系统不是一个只包含头的库;相反,它取决于已编译的组件。

下次,请突出显示您的代码并点击
Ctrl+K
或使用
{}编辑器中的
按钮。标记
德语
已作为的一部分删除。您的意思是我需要将我的命令行更改为:g++-lboost_filesystem-o pr3 pr3.cppI在我的命令行末尾添加了-lboost_filesystem:g++-o pr3 pr3.cpp-lboost_filesystem但是,我现在得到这个输出:/usr/bin/ld:/tmp/ccKa219G.o:对符号“boost::system::system_category()”的未定义引用/usr/bin/ld:note:'boost::system::system_category()'是在DSO/usr/lib/libboost_系统中定义的。因此,请尝试将其添加到链接器命令行/usr/lib/libboost_系统中。so.1.46.1:无法读取符号:无效操作collect2:ld返回的结束状态为1@KG6ZVP:同时添加
-lboost\u系统
。在标题下,只有库才会告诉您哪些库需要库引用。@当我看到您的链接时,我正打算为所有这些boost编译内容请求一个引用。谢谢
#include <boost/filesystem.hpp>
#include <iostream>

int main(){
  boost::filesystem::path p("C:\\Windows\\System");
  std::cout << p.root_name() << std::endl; 
  std::cout << p.root_directory() << std::endl; 
  std::cout << p.root_path() << std::endl; 
  std::cout << p.relative_path() << std::endl; 
  std::cout << p.parent_path() << std::endl; 
  std::cout << p.filename() << std::endl; 
} 
sam@sam-MT6707:~/Dokumente/Programming/Projekte/FTP-abgleicher$ g++ -o pr3 pr3.cpp
/tmp/ccrN7yHl.o: In function `main':
pr3.cpp:(.text+0x3b): undefined reference to `boost::filesystem3::path::root_name() const'
pr3.cpp:(.text+0x7e): undefined reference to `boost::filesystem3::path::root_directory() const'
pr3.cpp:(.text+0xc1): undefined reference to `boost::filesystem3::path::root_path() const'
pr3.cpp:(.text+0x104): undefined reference to `boost::filesystem3::path::relative_path() const'
pr3.cpp:(.text+0x147): undefined reference to `boost::filesystem3::path::parent_path() const'
pr3.cpp:(.text+0x18a): undefined reference to `boost::filesystem3::path::filename() const'
pr3.cpp:(.text+0x1e8): undefined reference to `boost::filesystem3::path::stem() const'
pr3.cpp:(.text+0x22b): undefined reference to `boost::filesystem3::path::extension() const'

/tmp/ccrN7yHl.o: In function `__static_initialization_and_destruction_0(int, int)':
pr3.cpp:(.text+0x364): undefined reference to `boost::system::generic_category()'
pr3.cpp:(.text+0x36e): undefined reference to `boost::system::generic_category()'
pr3.cpp:(.text+0x378): undefined reference to `boost::system::system_category()'
/tmp/ccrN7yHl.o: In function `boost::filesystem3::path::codecvt()':
pr3.cpp:(.text._ZN5boost11filesystem34path7codecvtEv[boost::filesystem3::path::codecvt()]+0x7): undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()'
collect2: ld gab 1 als Ende-Status zurück

^Translation of last line: ld returned an end status of 1