cmake make 出错。
weaweawe01 opened this issue · 2 comments
weaweawe01 commented
因为main.cpp 调用了 `std::filesystem 这个为C++17 的新功能。当前配置的gcc 设置了C++17 也会出现报错。
path.cpp:(.text._ZNSt10filesystem7__cxx114pathC2IPcS1_EERKT_NS1_6formatE[_ZNSt10filesystem7__cxx114pathC5IPcS1_EERKT_NS1_6formatE]+0x64): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/pangolin.dir/build.make:146: bin/pangolin] Error 1
make[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/pangolin.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
应该修改CMakeLists.txt 最后一行为
target_link_libraries(pangolin zero $<$BOOL:${STATIC_BUILD}:-static-pie> stdc++fs)
[root@localhost pangolin]# cmake --version
cmake version 3.20.2
[root@localhost pangolin]# make
Consolidate compiler generated dependencies of target zero
[ 7%] Building CXX object _deps/zero-build/CMakeFiles/zero.dir/src/log.cpp.o
[ 14%] Building CXX object _deps/zero-build/CMakeFiles/zero.dir/src/time/date.cpp.o
[ 21%] Building CXX object _deps/zero-build/CMakeFiles/zero.dir/src/strings/strings.cpp.o
[ 28%] Building CXX object _deps/zero-build/CMakeFiles/zero.dir/src/proc/process.cpp.o
[ 35%] Building CXX object _deps/zero-build/CMakeFiles/zero.dir/src/atomic/event.cpp.o
[ 42%] Building CXX object _deps/zero-build/CMakeFiles/zero.dir/src/filesystem/path.cpp.o
[ 50%] Building CXX object _deps/zero-build/CMakeFiles/zero.dir/src/encoding/base64.cpp.o
[ 57%] Building CXX object _deps/zero-build/CMakeFiles/zero.dir/src/encoding/hex.cpp.o
[ 64%] Linking CXX static library ../../lib/libzero.a
[ 64%] Built target zero
Consolidate compiler generated dependencies of target pangolin
[ 71%] Building CXX object CMakeFiles/pangolin.dir/main.cpp.o
[ 78%] Building CXX object CMakeFiles/pangolin.dir/ptrace/tracee.cpp.o
[ 85%] Building CXX object CMakeFiles/pangolin.dir/ptrace/executor.cpp.o
[ 92%] Building CXX object CMakeFiles/pangolin.dir/inject/injector.cpp.o
[100%] Linking CXX executable bin/pangolin
[100%] Built target pangolin
[root@localhost pangolin]# cat CMakeLists.txt
weaweawe01 commented
Hackerl commented
我知道这个问题,gcc8 默认没有链接 filesystem,但是 gcc9 以上的版本已经没有这个问题了。
我理解这是特殊版本的编译器导致的,所以没有在 CMakeLists 里添加相关代码。