Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Error trying to use modules, import function unknown?
Forum Updated to NodeBB v4.3 + New Features

Error trying to use modules, import function unknown?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
8 Posts 4 Posters 245 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.
  • C Offline
    C Offline
    Colins2
    wrote on 30 Apr 2025, 04:13 last edited by
    #1

    Hi,
    I am doing a course on 'modern' C++ and using the following in CMakeLists.txt:
    #Require C++23
    set(CXX_STANDARD_REQUIRED ON) #Make C++23 a hard requirement
    set(CMAKE_CXX_STANDARD 23) # Default C++ standard for targets
    set(CMAKE_CXX_SCAN_FOR_MODULES ON)
    The course instructor is using VS Code to write the code examples. I also have VS Code installed and these little code snippets work fine when compiled from the Code IDE but will not work using QtCreator as the IDE.
    I am using the same compilers, either Clang 19.1 or GCC 13.3.0 as this is the latest version in the Mint repos.
    The code is very simple and just puts 'import utilities' (the file utilities.ixx) after the #includes and before main().
    The error I get from QtCreator is that the compiler doesn't understand import and yet the same compiler and cmake understands them perfectly when compiling from the Code IDE?
    I really prefer using the QtCreator IDE to VS Code but I can't get past this problem and I can't even say for sure where the problem lies.
    Any ideas / suggestions welcome
    Colin

    J 1 Reply Last reply 30 Apr 2025, 04:59
    0
    • S Offline
      S Offline
      Shrishashank
      wrote on 30 Apr 2025, 04:42 last edited by
      #2

      Hi Colin,

      The issue might be with how QtCreator handles C++23 modules compared to Visual Studio Code. Here are some quick steps to troubleshoot:

      Check CMake Settings: Ensure CMAKE_CXX_STANDARD and CMAKE_CXX_SCAN_FOR_MODULES are applied in QtCreator.

      Enable Module Flags: Add -fmodules-ts for GCC or -std=c++23 explicitly in QtCreator's build settings.

      Compare Build Logs: Look for differences between the build logs of QtCreator and VS Code to find missing flags or settings.

      Update QtCreator: Ensure you're using the latest version for proper C++23 module support.

      If all else fails, stick with Visual Studio Code for this particular setup or report the issue to QtCreator's team for clarification.

      Hope this helps!

      SHRISHASHANK S K

      C 1 Reply Last reply 30 Apr 2025, 12:50
      0
      • C Colins2
        30 Apr 2025, 04:13

        Hi,
        I am doing a course on 'modern' C++ and using the following in CMakeLists.txt:
        #Require C++23
        set(CXX_STANDARD_REQUIRED ON) #Make C++23 a hard requirement
        set(CMAKE_CXX_STANDARD 23) # Default C++ standard for targets
        set(CMAKE_CXX_SCAN_FOR_MODULES ON)
        The course instructor is using VS Code to write the code examples. I also have VS Code installed and these little code snippets work fine when compiled from the Code IDE but will not work using QtCreator as the IDE.
        I am using the same compilers, either Clang 19.1 or GCC 13.3.0 as this is the latest version in the Mint repos.
        The code is very simple and just puts 'import utilities' (the file utilities.ixx) after the #includes and before main().
        The error I get from QtCreator is that the compiler doesn't understand import and yet the same compiler and cmake understands them perfectly when compiling from the Code IDE?
        I really prefer using the QtCreator IDE to VS Code but I can't get past this problem and I can't even say for sure where the problem lies.
        Any ideas / suggestions welcome
        Colin

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 30 Apr 2025, 04:59 last edited by
        #3

        @Colins2 Do you get this error when you compile the project or just in the QtCreator editor?
        Did you make sure that the C++ standard flag was passed to the compiler?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        C 1 Reply Last reply 30 Apr 2025, 12:36
        0
        • J jsulm
          30 Apr 2025, 04:59

          @Colins2 Do you get this error when you compile the project or just in the QtCreator editor?
          Did you make sure that the C++ standard flag was passed to the compiler?

          C Offline
          C Offline
          Colins2
          wrote on 30 Apr 2025, 12:36 last edited by Colins2
          #4

          @jsulm I get the error compiling the project.
          Here is my CMakeLists.txt:
          cmake_minimum_required(VERSION 3.28)
          set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")

          project(lambdas LANGUAGES CXX)

          set(CMAKE_CXX_STANDARD 23)
          set(CMAKE_CXX_STANDARD_REQUIRED ON)
          set(CMAKE_CXX_SCAN_FOR_MODULES ON)

          add_executable(lambdas
          main.cpp
          vcpkg.json
          utilities.ixx
          )

          find_package(fmt CONFIG REQUIRED)

          include(GNUInstallDirs)
          install(TARGETS lambdas
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
          )
          target_link_libraries(${PROJECT_NAME} PRIVATE fmt::fmt)

          All the required flags should be passed, as far as I can see.

          Here is the error:
          Qt-module.png

          1 Reply Last reply
          0
          • S Shrishashank
            30 Apr 2025, 04:42

            Hi Colin,

            The issue might be with how QtCreator handles C++23 modules compared to Visual Studio Code. Here are some quick steps to troubleshoot:

            Check CMake Settings: Ensure CMAKE_CXX_STANDARD and CMAKE_CXX_SCAN_FOR_MODULES are applied in QtCreator.

            Enable Module Flags: Add -fmodules-ts for GCC or -std=c++23 explicitly in QtCreator's build settings.

            Compare Build Logs: Look for differences between the build logs of QtCreator and VS Code to find missing flags or settings.

            Update QtCreator: Ensure you're using the latest version for proper C++23 module support.

            If all else fails, stick with Visual Studio Code for this particular setup or report the issue to QtCreator's team for clarification.

            Hope this helps!

            C Offline
            C Offline
            Colins2
            wrote on 30 Apr 2025, 12:50 last edited by
            #5

            @Shrishashank said in Error trying to use modules, import function unknown?:
            Hi, thanks for the response.
            The settings in CMakeLists.txt should be correct. See the answer to jsulm where I posted it.
            I am using the latest version of QtCreator but I don't see why that should make a difference as the error seems to be a CMake one.
            What is confusing me is that the code compiles and runs from VS Code using the same compiler(s).
            Colin

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Colins2
              wrote on 1 May 2025, 14:20 last edited by
              #6

              I've found the problem but not the solution!
              Whatever I set in kits or project Qt always defaults back to /usr/bin/gcc, which is version 13......
              I have installed gcc 14.2 through Homebrew but I can't get Qt to recognize it.
              I also have Clang 19.1 with the same problem.
              This is why I am unable to use the modules as it only works with gcc14.
              Short of actually uninstalling gcc13, I can't think of what else to do.
              As mentioned above, Code, though I hate to admit it, works OK. I can select any installed compiler to use.
              Colin

              S 1 Reply Last reply 2 May 2025, 06:49
              0
              • C Colins2
                1 May 2025, 14:20

                I've found the problem but not the solution!
                Whatever I set in kits or project Qt always defaults back to /usr/bin/gcc, which is version 13......
                I have installed gcc 14.2 through Homebrew but I can't get Qt to recognize it.
                I also have Clang 19.1 with the same problem.
                This is why I am unable to use the modules as it only works with gcc14.
                Short of actually uninstalling gcc13, I can't think of what else to do.
                As mentioned above, Code, though I hate to admit it, works OK. I can select any installed compiler to use.
                Colin

                S Offline
                S Offline
                SimonSchroeder
                wrote on 2 May 2025, 06:49 last edited by
                #7

                @Colins2 said in Error trying to use modules, import function unknown?:

                I have installed gcc 14.2 through Homebrew but I can't get Qt to recognize it.
                I also have Clang 19.1 with the same problem.

                QtCreator does not always find all installations of compilers (only those in standard paths). However, you can manually add compilers. Then, you copy an existing kit (a kit is a combination of Qt version and compiler) and change its compiler to the one you added manually.

                Once you have the proper kit you need to add a new build configuration under "Projects". Make sure to use a totally different folder as before (or delete the old one). CMake will remember the previous configuration and will not change the compiler if you are reusing the same folder.

                C 1 Reply Last reply 27 days ago
                0
                • S SimonSchroeder
                  2 May 2025, 06:49

                  @Colins2 said in Error trying to use modules, import function unknown?:

                  I have installed gcc 14.2 through Homebrew but I can't get Qt to recognize it.
                  I also have Clang 19.1 with the same problem.

                  QtCreator does not always find all installations of compilers (only those in standard paths). However, you can manually add compilers. Then, you copy an existing kit (a kit is a combination of Qt version and compiler) and change its compiler to the one you added manually.

                  Once you have the proper kit you need to add a new build configuration under "Projects". Make sure to use a totally different folder as before (or delete the old one). CMake will remember the previous configuration and will not change the compiler if you are reusing the same folder.

                  C Offline
                  C Offline
                  Colins2
                  wrote 27 days ago last edited by
                  #8

                  @SimonSchroeder That's a very important point!
                  I have solved my immediate problems like this:
                  I deleted GCC-13 from the kits/compilers.
                  I used sudo update-alternatives to make /usr/bin/gcc point to my GCC14.2 homebrew installation.
                  That worked partially but GCC-14.2 doesn't handle modules properly and nor does it reliably handle vcpkg packages!
                  (I have been using clang-19.1 with VS Code for the project/tutorials mentioned above and that does work)
                  I struggled to get QtCreator to use the clang compiler but at last found the solution, albeit using a sledgehammer to crack a nut!

                  1. Delete GCC entries from the Kits/compilers section. My Qt installation already found clang as it was in my path.
                  2. Added 'export $CXX=clang to my .bashrc. Not sure how necessary this is but it was mentioned in an error message.
                    3)Added the line "set(CMAKE_CXX_COMPILER clang++)" to CMakeLists before "project(helloClang LANGUAGES CXX)"
                    Now my little helloClang compiles with the clang compiler.
                    I added a vcpkg statement and the fmt library with the appropriate lines in CMakeLists - and it works!
                    I haven't had time to try out modules yet but I'm sure they will work as well.

                  I don't think it was really necessary to delete the GCC kits, probably setting the compiler in CMakeLists may be enough.
                  I will continue experimenting to see what works.
                  None of this is necessary in VS Code, it's a simple drop-down menu to select the compiler when configuring initially. Also, there are no entries in the CMakeLists file nor environmental variables set.
                  An equivalent in QtCreator would be to just go to the kits page and select the wanted compiler and click Apply/OK but this does not work.
                  I'm just pleased that I will be able to use modules and vcpkg packages from QtCreator now.

                  1 Reply Last reply
                  0
                  • C Colins2 has marked this topic as solved 27 days ago

                  • Login

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