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. Qt + CMake no moc files genereated
Qt 6.11 is out! See what's new in the release blog

Qt + CMake no moc files genereated

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
17 Posts 4 Posters 12.2k Views 3 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
    ceora
    wrote on last edited by
    #5

    i just re-read the first-post and as you can see the

    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    

    is already set...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      Right, I managed to miss it...

      Which version of CMake and Qt are you using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ceora
        wrote on last edited by
        #7

        Cmake version 3.7.0 and Qt 5.7

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #8

          Ok, can you share the code you have to reproduce your problem ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ceora
            wrote on last edited by
            #9

            of corse! The cmake file is the same i posted in the previous post

            test.h

            #include <QObject>
            
            class Test : public QObject
            {
              Q_OBJECT
            public:
              Test();
              virtual ~Test() {}
            };
            
            

            test.cpp

            #include "test.h"
            
            Test::Test()
            {}
            

            main.cpp

            #include <iostream>
            #include <QCoreApplication>
            #include <QDebug>
            
            #include "test.h"
            
            using namespace std;
            
            int main(int argc, char *argv[])
            {
              QCoreApplication a(argc, argv);
              Test t;
              t.setObjectName("Test");
              qDebug() << t.objectName();
            
              return a.exec();
            }
            

            instead if you prefer the "real project"(the errors are pretty the same)..
            github repo
            to compile it you need tinyXML2. There is the working .pro file and the non working cmake file.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mchinand
              wrote on last edited by
              #10

              Isn't moc only needed if your QObject class has signals and/or slots?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ceora
                wrote on last edited by
                #11

                I think it's needed only the Q_OBJECT macro to activate moc, signals and slots are inherited from QObject.

                1 Reply Last reply
                1
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  @ceora That's not the problem at hand it's the automoc not running properly.

                  @ceora try with:

                  cmake_minimum_required(VERSION 2.8.11)
                  
                  project(CMake_Test2)
                  
                  set(CMAKE_INCLUDE_CURRENT_DIR ON)
                  set(CMAKE_AUTOMOC ON)
                  
                  find_package(Qt5Core)
                  
                  file(GLOB SOURCES *.cpp)
                  
                  add_executable(${PROJECT_NAME} ${SOURCES})
                  target_link_libraries(${PROJECT_NAME} Qt5::Core)
                  

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • C ceora

                    Hi, I'm trying to build a simple QCoreApplication prorgam using CMake as a project files.
                    At time of building I get link error to Qt meta, the ones that shoul be generated with moc.

                    I followed the documentation on cmake and qt on how to set up a project, but Automoc does'nt work

                    this is my cmake file:

                    project(CMake_Test2)
                    cmake_minimum_required(VERSION 2.8)
                    
                    aux_source_directory(. SRC_LIST)
                    
                    find_package(Qt5 COMPONENTS core REQUIRED)
                    set(CMAKE_AUTOMOC ON)
                    set(CMAKE_INCLUDE_CURRENT_DIR ON)
                    
                    add_executable(${PROJECT_NAME} ${SRC_LIST})
                    
                    target_link_libraries(${PROJECT_NAME} Qt5::Core)
                    

                    the source files are a simple helloworld main.cpp file and two files containing a simple QObject
                    definition and declaration(just to test the moc generation)

                    A Offline
                    A Offline
                    ambershark
                    wrote on last edited by
                    #13

                    Your example and code worked fine for me with one exception. This line had to be changed to a capital C on core:

                    find_package(Qt5 COMPONENTS Core REQUIRED)

                    Here is the build output with make VERBOSE=1:

                    -- The C compiler identification is GNU 6.2.1
                    -- The CXX compiler identification is GNU 6.2.1
                    -- Check for working C compiler: /usr/bin/cc
                    -- Check for working C compiler: /usr/bin/cc -- works
                    -- Detecting C compiler ABI info
                    -- Detecting C compiler ABI info - done
                    -- Detecting C compile features
                    -- Detecting C compile features - done
                    -- Check for working CXX compiler: /usr/bin/c++
                    -- Check for working CXX compiler: /usr/bin/c++ -- works
                    -- Detecting CXX compiler ABI info
                    -- Detecting CXX compiler ABI info - done
                    -- Detecting CXX compile features
                    -- Detecting CXX compile features - done
                    -- Configuring done
                    -- Generating done
                    -- Build files have been written to: /home/mike/tmp/x/build
                    /usr/bin/cmake -H/home/mike/tmp/x -B/home/mike/tmp/x/build --check-build-system CMakeFiles/Makefile.cmake 0
                    /usr/bin/cmake -E cmake_progress_start /home/mike/tmp/x/build/CMakeFiles /home/mike/tmp/x/build/CMakeFiles/progress.marks
                    make -f CMakeFiles/Makefile2 all
                    make[1]: Entering directory '/home/mike/tmp/x/build'
                    make -f CMakeFiles/CMake_Test2_automoc.dir/build.make CMakeFiles/CMake_Test2_automoc.dir/depend
                    make[2]: Entering directory '/home/mike/tmp/x/build'
                    cd /home/mike/tmp/x/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mike/tmp/x /home/mike/tmp/x /home/mike/tmp/x/build /home/mike/tmp/x/build /home/mike/tmp/x/build/CMakeFiles/CMake_Test2_automoc.dir/DependInfo.cmake --color=
                    Dependee "/home/mike/tmp/x/build/CMakeFiles/CMake_Test2_automoc.dir/DependInfo.cmake" is newer than depender "/home/mike/tmp/x/build/CMakeFiles/CMake_Test2_automoc.dir/depend.internal".
                    Dependee "/home/mike/tmp/x/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/mike/tmp/x/build/CMakeFiles/CMake_Test2_automoc.dir/depend.internal".
                    Scanning dependencies of target CMake_Test2_automoc
                    make[2]: Leaving directory '/home/mike/tmp/x/build'
                    make -f CMakeFiles/CMake_Test2_automoc.dir/build.make CMakeFiles/CMake_Test2_automoc.dir/build
                    make[2]: Entering directory '/home/mike/tmp/x/build'
                    [ 20%] Automatic moc for target CMake_Test2
                    /usr/bin/cmake -E cmake_autogen /home/mike/tmp/x/build/CMakeFiles/CMake_Test2_automoc.dir/ ""
                    AUTOGEN: Checking /home/mike/tmp/x/main.cpp
                    AUTOGEN: Checking /home/mike/tmp/x/test.cpp
                    AUTOGEN: Checking /home/mike/tmp/x/test.h
                    Generating moc source moc_test.cpp
                    /usr/local/Qt/bin/moc -I/home/mike/tmp/x/build -I/home/mike/tmp/x -I/usr/local/Qt/include -I/usr/local/Qt/include/QtCore -I/usr/local/Qt/./mkspecs/linux-g++ -DQT_CORE_LIB -DQT_NO_DEBUG -o /home/mike/tmp/x/build/moc_test.cpp /home/mike/tmp/x/test.h
                    Generating moc compilation CMake_Test2_automoc.cpp
                    make[2]: Leaving directory '/home/mike/tmp/x/build'
                    [ 20%] Built target CMake_Test2_automoc
                    make -f CMakeFiles/CMake_Test2.dir/build.make CMakeFiles/CMake_Test2.dir/depend
                    make[2]: Entering directory '/home/mike/tmp/x/build'
                    cd /home/mike/tmp/x/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mike/tmp/x /home/mike/tmp/x /home/mike/tmp/x/build /home/mike/tmp/x/build /home/mike/tmp/x/build/CMakeFiles/CMake_Test2.dir/DependInfo.cmake --color=
                    Dependee "/home/mike/tmp/x/build/CMakeFiles/CMake_Test2.dir/DependInfo.cmake" is newer than depender "/home/mike/tmp/x/build/CMakeFiles/CMake_Test2.dir/depend.internal".
                    Dependee "/home/mike/tmp/x/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/mike/tmp/x/build/CMakeFiles/CMake_Test2.dir/depend.internal".
                    Scanning dependencies of target CMake_Test2
                    make[2]: Leaving directory '/home/mike/tmp/x/build'
                    make -f CMakeFiles/CMake_Test2.dir/build.make CMakeFiles/CMake_Test2.dir/build
                    make[2]: Entering directory '/home/mike/tmp/x/build'
                    [ 40%] Building CXX object CMakeFiles/CMake_Test2.dir/main.cpp.o
                    /usr/bin/c++   -DQT_CORE_LIB -DQT_NO_DEBUG -I/home/mike/tmp/x/build -I/home/mike/tmp/x -isystem /usr/local/Qt/include -isystem /usr/local/Qt/include/QtCore -isystem /usr/local/Qt/./mkspecs/linux-g++  -fPIC -std=gnu++11 -o CMakeFiles/CMake_Test2.dir/main.cpp.o -c /home/mike/tmp/x/main.cpp
                    [ 60%] Building CXX object CMakeFiles/CMake_Test2.dir/test.cpp.o
                    /usr/bin/c++   -DQT_CORE_LIB -DQT_NO_DEBUG -I/home/mike/tmp/x/build -I/home/mike/tmp/x -isystem /usr/local/Qt/include -isystem /usr/local/Qt/include/QtCore -isystem /usr/local/Qt/./mkspecs/linux-g++  -fPIC -std=gnu++11 -o CMakeFiles/CMake_Test2.dir/test.cpp.o -c /home/mike/tmp/x/test.cpp
                    [ 80%] Building CXX object CMakeFiles/CMake_Test2.dir/CMake_Test2_automoc.cpp.o
                    /usr/bin/c++   -DQT_CORE_LIB -DQT_NO_DEBUG -I/home/mike/tmp/x/build -I/home/mike/tmp/x -isystem /usr/local/Qt/include -isystem /usr/local/Qt/include/QtCore -isystem /usr/local/Qt/./mkspecs/linux-g++  -fPIC -std=gnu++11 -o CMakeFiles/CMake_Test2.dir/CMake_Test2_automoc.cpp.o -c /home/mike/tmp/x/build/CMake_Test2_automoc.cpp
                    [100%] Linking CXX executable CMake_Test2
                    /usr/bin/cmake -E cmake_link_script CMakeFiles/CMake_Test2.dir/link.txt --verbose=1
                    /usr/bin/c++      CMakeFiles/CMake_Test2.dir/main.cpp.o CMakeFiles/CMake_Test2.dir/test.cpp.o CMakeFiles/CMake_Test2.dir/CMake_Test2_automoc.cpp.o  -o CMake_Test2 -rdynamic /usr/local/Qt/lib/libQt5Core.so.5.7.0 -Wl,-rpath,/usr/local/Qt/lib
                    make[2]: Leaving directory '/home/mike/tmp/x/build'
                    [100%] Built target CMake_Test2
                    make[1]: Leaving directory '/home/mike/tmp/x/build'
                    /usr/bin/cmake -E cmake_progress_start /home/mike/tmp/x/build/CMakeFiles 0
                    

                    Again this used your test.h/cpp and main.cpp, as well as your posted CMakeFiles.txt. I used cmake 3.6.2 and Qt 5.7 for the test if that matters (it shouldn't).

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    1 Reply Last reply
                    1
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      @ambershark Nice catch ! I missed that one.

                      On a side note, aux_source_directory as used in the sample code goes against the CMake recommandation.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 1 Reply Last reply
                      1
                      • SGaistS SGaist

                        @ambershark Nice catch ! I missed that one.

                        On a side note, aux_source_directory as used in the sample code goes against the CMake recommandation.

                        A Offline
                        A Offline
                        ambershark
                        wrote on last edited by
                        #15

                        @SGaist Oh I would have missed it too if I didn't try to run his example. Case stuff is hard to see without a compiler issue. :)

                        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #16

                          I also ran it but I didn't saw anything about the component itself but I may have very well missed it.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            ceora
                            wrote on last edited by
                            #17

                            Tried both solutions: And both work! It seems that the capital c on core make the difference, now moc is triggered correctly. It work also for the "real project".

                            Thanks guys!!

                            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