Compilation issues when using #include<filesystem>
-
Here is my .pro
QT -= gui CONFIG += c++17 CONFIG += console CONFIG -= app_bundle # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
Here is my main.cpp
#include <QCoreApplication> #include <filesystem> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); return a.exec(); }
Here is the compiler output
g++ -c -fno-keep-inline-dllexport -g -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_QML_DEBUG -DQT_CORE_LIB -I../test -I. -IC:/Qt/6.0.4/mingw81_64/include -IC:/Qt/6.0.4/mingw81_64/include/QtCore -Idebug -IC:/Qt/6.0.4/mingw81_64/mkspecs/win32-g++ -o debug\main.o ..\test\main.cpp In file included from C:/Qt/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37, from ..\test\main.cpp:2: C:/Qt/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)': C:/Qt/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path') || (__p.has_root_name() && __p.root_name() != root_name()))
-
see the compiler notes here -> https://en.cppreference.com/w/cpp/filesystem
-
Thanks for the reply.
According to the link "Using this library may require additional compiler/linker options. GNU implementation prior to 9.1 requires linking with -lstdc++fs and LLVM implementation prior to LLVM 9.0 requires linking with -lc++fs"
So i added the following lines in .pro file
LIBS += -lstdc++fs
Still the same output.
P.S: I also tried
LIBS += -lc++fs
But the problem persists
-
Thanks for the reply.
According to the link "Using this library may require additional compiler/linker options. GNU implementation prior to 9.1 requires linking with -lstdc++fs and LLVM implementation prior to LLVM 9.0 requires linking with -lc++fs"
So i added the following lines in .pro file
LIBS += -lstdc++fs
Still the same output.
P.S: I also tried
LIBS += -lc++fs
But the problem persists
-
@pingal
I do not know what precisely you are supposed to do here. But the errors you show earlier are compilation errors, so adding linker flags is not going to resolve that.... -
@JonB exactly, that's the compilation errors and has nothing to do with the linker but i followed notes Kent-Dorfman has suggested
I think this is some sort of bug (when std::filesystem is used in QT)
@pingal said in Compilation issues when using #include<filesystem>:
I think this is some sort of bug (when std::filesystem is used in QT)
Well you could test that in a standalone program without Qt?
I have seen possible issues like https://www.reddit.com/r/cpp_questions/comments/f10d31/comment/fh11qat/?utm_source=reddit&utm_medium=web2x&context=3
Your issue is most likely with MINGW. Its GCC may not be complete/up-to-date.
Maybe you could play at https://godbolt.org/ ?
-
Your compiler version (mingw8.1.0) is not suitable for the Qt version you are trying to compile with (6.0.2).
See here for an overview.
More specifically: for the MinGW version you use, you have to#include<experimental/filesystem>
which is why you get the error.
With more recent compilers (e.g. GCC10 or MinGW 11.2),-lstdc++fs
is no longer necessary. If the missing linking instruction was the problem, you'd have had a linker rather than a compiler error.
BRgds
Axel -
@Axel-Spoerl That really helped.
I've added QT 6.2.3 along with MinGW 9.0.0 to QT Creator and the problem is solved.
-
@Axel-Spoerl That really helped.
I've added QT 6.2.3 along with MinGW 9.0.0 to QT Creator and the problem is solved.
@pingal how did you fix this bug I have the same issue
-
@pingal how did you fix this bug I have the same issue
-
Your compiler version (mingw8.1.0) is not suitable for the Qt version you are trying to compile with (6.0.2).
See here for an overview.
More specifically: for the MinGW version you use, you have to#include<experimental/filesystem>
which is why you get the error.
With more recent compilers (e.g. GCC10 or MinGW 11.2),-lstdc++fs
is no longer necessary. If the missing linking instruction was the problem, you'd have had a linker rather than a compiler error.
BRgds
AxelThis post is deleted! -
@rowan-Samy
Since @pingal already wroteI've added QT 6.2.3 along with MinGW 9.0.0 to QT Creator and the problem is solved.
what have you done?
This post is deleted! -
This post is deleted!
@rowan-Samy
Seriously?- Install Qt 6.2.3.
- Install (may come with the Qt version) and use (select as kit) MinGW 9.0.0.
- See whether your problem has gone away.
If not then it appears you have a different problem from @pingal so there's no point asking him what he did.