如何使用Qt避免std::filesystem链接器错误?
我想在g++版本Ubuntu 8.2.0-7ubuntu1的Qt5.12.0中使用如何使用Qt避免std::filesystem链接器错误?,qt,g++,c++17,std-filesystem,Qt,G++,C++17,Std Filesystem,我想在g++版本Ubuntu 8.2.0-7ubuntu1的Qt5.12.0中使用std::filesystem,但出现链接器错误: g++ -lstdc++fs -Wl,-rpath,/home/user/Qt/5.12.0/gcc_64/lib -o qf_filesystem_test main.o -L/home/user/Qt/5.12.0/gcc_64/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread /usr/bin/l
std::filesystem
,但出现链接器错误:
g++ -lstdc++fs -Wl,-rpath,/home/user/Qt/5.12.0/gcc_64/lib -o qf_filesystem_test main.o -L/home/user/Qt/5.12.0/gcc_64/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
/usr/bin/ld: main.o: in function `std::filesystem::exists(std::filesystem::__cxx11::path const&)':
/usr/include/c++/8/bits/fs_ops.h:121: undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
/usr/bin/ld: main.o: in function `std::filesystem::__cxx11::path::path<char*, std::filesystem::__cxx11::path>(char* const&, std::filesystem::__cxx11::path::format)':
/usr/include/c++/8/bits/fs_path.h:183: undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:257: qf_filesystem_test] Error 1
22:12:16: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project qf_filesystem_test (kit: Desktop Qt 5.12.0 GCC 64bit)
When executing step "Make"
我的.pro文件如下所示:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qf_filesystem_test
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
CONFIG += c++17
QMAKE_LFLAGS += -lstdc++fs
SOURCES += main.cpp
在使用g++进行了一些测试之后,我认为问题是由g++标志的顺序引起的,因为Qt将-lstdc++fs
放在前面
- 为什么我还需要使用此标志?我认为g++8已经支持C++17,只有当我想使用
时才需要这个标志std::experimental::filesystem
- 如何在Qt Creator中生成代码
是GCC 8()的独立库。正如你所怀疑的,你的问题是按照旗帜的顺序来处理的。在文档中稍微翻一翻,就会发现QMAKE\u LFLAGS
更多地用于链接器标志,而不是库加载,这就是为什么它会提前通过的原因(例如-O3
)
使用LIBS+=-lstdc++fs
应该可以替代
此解决方案归功于。将您的
CONFIG+=c++17
更改为CONFIG+=c++1z
没有帮助,相同的链接器错误仍然存在。