fatal error: filesystem缺失解决方法

fatal error: filesystem缺失解决方法

问题来源

elevation_mapping 需要用到 point_cloud_io 安装时遇到

fatal error: filesystem: No such file or directory
 #include <filesystem>
          ^~~~~~~~~~~~
compilation terminated.

解决方案

升级后重新编译,出现如下报错:

CMakeFiles/read.dir/src/Read.cpp.o: In function `point_cloud_io::Read::readFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
Read.cpp:(.text+0xc04): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
Read.cpp:(.text+0xc4d): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
Read.cpp:(.text+0xc55): undefined reference to `std::filesystem::__cxx11::path::_M_find_extension() const'
Read.cpp:(.text+0xd31): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
Read.cpp:(.text+0xda3): undefined reference to `std::filesystem::__cxx11::path::compare(std::filesystem::__cxx11::path const&) const'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/flipper/kindr_ws/devel/.private/point_cloud_io/lib/point_cloud_io/read] Error 1
make[1]: *** [CMakeFiles/read.dir/all] Error 2
make: *** [all] Error 2
  • 步骤2:修改cmakelist
    参考https://zhuanlan.zhihu.com/p/677041343了解到:
    1.在 GCC 8.4 中,std::filesystem 是作为一个单独的库(libstdc++fs)提供的
    2.在 GCC 8.4 使用 std::filesystem 的情况下,如果未明确指定 -lstdc++fs,编译器就不会链接这个库,从而导致链接错误
    因此可将cmakelist中build部分修改为如下:
###########
## Build ##
###########
add_executable(read
  src/read_node.cpp
  src/Read.cpp
)
target_link_libraries(read
  ${catkin_LIBRARIES}
  stdc++fs
)

add_executable(write
  src/write_node.cpp
  src/Write.cpp
)
target_link_libraries(write
  ${catkin_LIBRARIES}
  stdc++fs
)

之后重新编译即可。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值