在树莓派上编译失败并显示“ std :: filesystem”

时间:2020-05-22 10:38:40

标签: c++ std-filesystem

我在SD卡上安装了“ Raspberry Pi 3 Model B”和“带有桌面的Raspbian Buster”。

我安装了使用g ++进行编译所需的一切:

gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我创建了一个小的测试文件(test.cpp):

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
    for(fs::path p : {"/var/tmp/example.txt", "/", "/var/tmp/."})
        std::cout << "The parent path of " << p
                  << " is " << p.parent_path() << '\n';
}

并使用以下命令进行编译:

g++ -std=c++17 -Wall -Wextra -pedantic-errors test.cpp -o test

但是编译失败并显示错误:

/usr/bin/ld: /tmp/cckH4cTy.o: in function `main':
test.cpp:(.text+0xa4): undefined reference to `std::filesystem::__cxx11::path::parent_path() const'
/usr/bin/ld: /tmp/cckH4cTy.o: in function `std::filesystem::__cxx11::path::path<char const*, std::filesystem::__cxx11::path>(char const* const&, std::filesystem::__cxx11::path::format)':
test.cpp:(.text._ZNSt10filesystem7__cxx114pathC2IPKcS1_EERKT_NS1_6formatE[_ZNSt10filesystem7__cxx114pathC5IPKcS1_EERKT_NS1_6formatE]+0x70): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status

如何解决?

0 个答案:

没有答案