问题来源
elevation_mapping 需要用到 point_cloud_io 安装时遇到
fatal error: filesystem: No such file or directory
#include <filesystem>
^~~~~~~~~~~~
compilation terminated.
解决方案
- 步骤1:升级gcc到gcc-8
参考https://blog.csdn.net/weixin_45867382/article/details/130930112中的步骤升级。
升级后重新编译,出现如下报错:
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
)
之后重新编译即可。
2201

被折叠的 条评论
为什么被折叠?



