Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Compilation issues when using #include<filesystem>
Forum Updated to NodeBB v4.3 + New Features

Compilation issues when using #include<filesystem>

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pingal
    wrote on last edited by pingal
    #1

    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()))
    

    Capture.PNG

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      see the compiler notes here -> https://en.cppreference.com/w/cpp/filesystem

      1 Reply Last reply
      1
      • P Offline
        P Offline
        pingal
        wrote on last edited by
        #3

        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

        JonBJ 1 Reply Last reply
        0
        • P pingal

          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

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @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....

          P 1 Reply Last reply
          0
          • JonBJ JonB

            @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....

            P Offline
            P Offline
            pingal
            wrote on last edited by pingal
            #5

            @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)

            JonBJ 1 Reply Last reply
            0
            • P pingal

              @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)

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @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/ ?

              1 Reply Last reply
              0
              • Axel SpoerlA Offline
                Axel SpoerlA Offline
                Axel Spoerl
                Moderators
                wrote on last edited by Axel Spoerl
                #7

                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

                Software Engineer
                The Qt Company, Oslo

                R 1 Reply Last reply
                5
                • P Offline
                  P Offline
                  pingal
                  wrote on last edited by
                  #8

                  @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.

                  R 1 Reply Last reply
                  0
                  • P pingal

                    @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.

                    R Offline
                    R Offline
                    rowan Samy
                    wrote on last edited by
                    #9

                    @pingal how did you fix this bug I have the same issue

                    JonBJ 1 Reply Last reply
                    0
                    • R rowan Samy

                      @pingal how did you fix this bug I have the same issue

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #10

                      @rowan-Samy
                      Since @pingal already wrote

                      I've added QT 6.2.3 along with MinGW 9.0.0 to QT Creator and the problem is solved.

                      what have you done?

                      R 1 Reply Last reply
                      0
                      • Axel SpoerlA Axel Spoerl

                        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

                        R Offline
                        R Offline
                        rowan Samy
                        wrote on last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • JonBJ JonB

                          @rowan-Samy
                          Since @pingal already wrote

                          I've added QT 6.2.3 along with MinGW 9.0.0 to QT Creator and the problem is solved.

                          what have you done?

                          R Offline
                          R Offline
                          rowan Samy
                          wrote on last edited by
                          #12
                          This post is deleted!
                          JonBJ 1 Reply Last reply
                          0
                          • R rowan Samy

                            This post is deleted!

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by JonB
                            #13

                            @rowan-Samy
                            Seriously?

                            1. Install Qt 6.2.3.
                            2. Install (may come with the Qt version) and use (select as kit) MinGW 9.0.0.
                            3. 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.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved