gpt4 book ai didi

c++ boost::filesystem undefined reference to `boost::filesystem3::path::root_name() const'

转载 作者:IT老高 更新时间:2023-10-28 22:00:55 28 4
gpt4 key购买 nike

在尝试编译利用 boost::filesystem 库的代码时,我一直遇到错误。我不明白我得到的任何编译器输出。这是我从 http://www.highscore.de/cpp/boost/dateisystem.html#dateisystem_pfadangaben 复制的代码:

#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;
}

我有 Ubuntu 11.10,我已经安装了 libbost-dev 和 g++。这是终端的样子:

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

我做错了什么?

最佳答案

您必须与 -lboost_filesystem -lboost_system 链接。 Boost 文件系统不是一个只有头文件的库;相反,它依赖于已编译的组件。

关于c++ boost::filesystem undefined reference to `boost::filesystem3::path::root_name() const',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7972314/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com