我在 SD 卡上安装了带有“Raspbian Buster with desktop”的“Raspberry Pi 3 Model B”。
我安装了使用 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
怎么解决 ?