CLion 文件系统链接器问题,即使使用 -lstdc++fs
CLion filesystem linker problem even with -lstdc++fs
我尝试在 Fedora 29 环境下的 CLion 项目中使用 <filesystem>
。
当直接从终端编译时,它运行顺利,但是当我尝试从 CLion 编译时,存在关于文件系统的链接器问题。我不确定我还能做什么。有什么建议吗?
- g++ (GCC) 8.3.1 20190223(红帽 8.3.1-2)
- clang 版本 7.0.1
(Fedora 7.0.1-6.fc29)
这是我已经尝试过的方法:
我添加了标志 -lstdc++fs:
set(CMAKE_CXX_FLAGS -lstdc++fs)
但我没有工作。我已验证此标志是否正在被以下人员使用:
set( CMAKE_VERBOSE_MAKEFILE on )
似乎是:
[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o
/usr/bin/g++ -lstdc++fs -g -std=gnu++17 -o
CMakeFiles/untitled.dir/main.cpp.o -c
/home/patryk/CLionProjects/untitled/main.cpp
[100%] Linking CXX executable untitled
/home/patryk/clion-2018.3.4/bin/cmake/linux/bin/cmake -E
cmake_link_script CMakeFiles/untitled.dir/link.txt --verbose=1
/usr/bin/g++ -lstdc++fs -g CMakeFiles/untitled.dir/main.cpp.o -o
untitled
/usr/bin/ld: CMakeFiles/untitled.dir/main.cpp.o: in function
`std::filesystem::__cxx11::path::path<char [2],
std::filesystem::__cxx11::path>(char const (&) [2],
std::filesystem::__cxx11::path::format)':
/usr/include/c++/8/bits/fs_path.h:184: undefined reference to
`std::filesystem::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status
我也试过使用 clang 编译器得到完全相同的结果。
main.cpp
#include <iostream>
#include <filesystem>
int main() {
std::filesystem::path p("D");
return 0;
}
CMake
使用 target_link_libraries
添加 -l
链接器标志。
target_link_libraries(your_executable stdc++fs)
为什么 set(CMAKE_CXX_FLAGS -lstdc++fs)
不起作用:-l
选项必须设置 在 您的源文件或目标文件之后。
c++ -lstdc++fs some_object.o -o executable # not working
c++ some_object.o -o executable -lstdc++fs # should work
我尝试在 Fedora 29 环境下的 CLion 项目中使用 <filesystem>
。
当直接从终端编译时,它运行顺利,但是当我尝试从 CLion 编译时,存在关于文件系统的链接器问题。我不确定我还能做什么。有什么建议吗?
- g++ (GCC) 8.3.1 20190223(红帽 8.3.1-2)
- clang 版本 7.0.1 (Fedora 7.0.1-6.fc29)
这是我已经尝试过的方法:
我添加了标志 -lstdc++fs:
set(CMAKE_CXX_FLAGS -lstdc++fs)
但我没有工作。我已验证此标志是否正在被以下人员使用:
set( CMAKE_VERBOSE_MAKEFILE on )
似乎是:
[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o
/usr/bin/g++ -lstdc++fs -g -std=gnu++17 -o
CMakeFiles/untitled.dir/main.cpp.o -c
/home/patryk/CLionProjects/untitled/main.cpp
[100%] Linking CXX executable untitled
/home/patryk/clion-2018.3.4/bin/cmake/linux/bin/cmake -E
cmake_link_script CMakeFiles/untitled.dir/link.txt --verbose=1
/usr/bin/g++ -lstdc++fs -g CMakeFiles/untitled.dir/main.cpp.o -o
untitled
/usr/bin/ld: CMakeFiles/untitled.dir/main.cpp.o: in function
`std::filesystem::__cxx11::path::path<char [2],
std::filesystem::__cxx11::path>(char const (&) [2],
std::filesystem::__cxx11::path::format)':
/usr/include/c++/8/bits/fs_path.h:184: undefined reference to
`std::filesystem::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status
我也试过使用 clang 编译器得到完全相同的结果。
main.cpp
#include <iostream>
#include <filesystem>
int main() {
std::filesystem::path p("D");
return 0;
}
CMake
使用 target_link_libraries
添加 -l
链接器标志。
target_link_libraries(your_executable stdc++fs)
为什么 set(CMAKE_CXX_FLAGS -lstdc++fs)
不起作用:-l
选项必须设置 在 您的源文件或目标文件之后。
c++ -lstdc++fs some_object.o -o executable # not working
c++ some_object.o -o executable -lstdc++fs # should work