IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Qt Discussion :

[CMake] compilation projet qt


Sujet :

Qt

  1. #1
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 92
    Points : 116
    Points
    116
    Par défaut [CMake] compilation projet qt
    Bonjour,

    cela fait deux jours que je m'arrache les cheveux à utiliser cmake.
    Mon projet compile bien avec qmake mais pas avec cmake.

    Voici l'organisation de mon projet :
    dans la racine :

    - un dossier compilation. Il est vide, c'est depuis ce dossier que je lance la commande cmake.

    - un dossier bin. C'est la que le fichier binaire executable doit etre placé par cmake.

    - un dossier test. Il ne contient que le fichier contenant mon main().

    - plusieurs dossiers contenant differentes classes

    Voici mes CMakeLists.txt :
    Celui situe a la racine du projet :
    PROJECT (INTERFACE)

    CMAKE_MINIMUM_REQUIRED (VERSION 2.6)

    SET (CMAKE_BUILD_TYPE Release)
    SET (CMAKE_VERBOSE_MAKEFILE true)

    SET (INTERFACE_DIR ${CMAKE_SOURCE_DIR} )
    SET (INTERFACE_SOURCE_DIR ${INTERFACE_DIR}/test ${INTERFACE_DIR}/manager ${INTERFACE_DIR}/player ${INTERFACE_DIR}/tree ${INTERFACE}/mainwindow )

    ADD_DEFINITIONS( -Wall -g -O2 -pipe)

    FIND_PACKAGE (Qt4 REQUIRED)
    INCLUDE( ${QT_USE_FILE} )

    SET (LIBRARY_OUTPUT_PATH ${INTERFACE_DIR}/build)
    SET (EXECUTABLE_OUTPUT_PATH ${INTERFACE_DIR}/bin)

    ADD_SUBDIRECTORY (player)
    ADD_SUBDIRECTORY (manager)
    ADD_SUBDIRECTORY (tree)
    ADD_SUBDIRECTORY (mainwindow)
    ADD_SUBDIRECTORY (test)
    Celui du repertoire test:
    INCLUDE_DIRECTORIES(
    ${LIBRARY_OUTPUT_PATH}
    ${INTERFACE_SOURCE_DIR}
    ${INTERFACE_MAINWINDOW_SOURCE_DIR}
    ${INTERFACE_SAMPLERMANAGER_SOURCE_DIR}
    ${INTERFACE_TREE_SOURCE_DIR}
    ${INTERFACE_PLAYER_SOURCE_DIR}
    )

    LINK_DIRECTORIES( ${LIBRARY_OUTPUT_PATH} )

    ADD_EXECUTABLE(executable main.cpp)

    TARGET_LINK_LIBRARIES(executable Tree_LIB Player_LIB SamplerManager_LIB MainWindow_LIB ${QT_LIBRARIES} )
    Celui d'un repertoire contenant differents classes :
    PROJECT(INTERFACE_PLAYER)

    INCLUDE_DIRECTORIES(
    ${INTERFACE_NEWMAT_SOURCE_DIR}
    ${INTERFACE_SOURCE_DIR}
    )

    ADD_LIBRARY(Player_LIB
    player.h
    player.cpp
    )
    Et pour finir voici le mesage d'erreur que j'obtientts à la toute fin de compilation :
    [100%] Building CXX object test/CMakeFiles/executable.dir/main.cpp.o
    cd /home/pierrick/files/projet-synthese/devlpt/devlpt/compilation/test && /usr/bin/c++ -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NO_DEBUG -O3 -DNDEBUG -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -I/home/pierrick/files/projet-synthese/devlpt/devlpt/build -I/home/pierrick/files/projet-synthese/devlpt/devlpt/test -I/home/pierrick/files/projet-synthese/devlpt/devlpt/manager -I/home/pierrick/files/projet-synthese/devlpt/devlpt/player -I/home/pierrick/files/projet-synthese/devlpt/devlpt/tree -I/mainwindow -I/home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow -Wall -g -O2 -pipe -o CMakeFiles/executable.dir/main.cpp.o -c /home/pierrick/files/projet-synthese/devlpt/devlpt/test/main.cpp
    Linking CXX executable ../../bin/executable
    cd /home/pierrick/files/projet-synthese/devlpt/devlpt/compilation/test && /usr/bin/cmake -E cmake_link_script CMakeFiles/executable.dir/link.txt --verbose=1
    /usr/bin/c++ -O3 -DNDEBUG -fPIC CMakeFiles/executable.dir/main.cpp.o -o ../../bin/executable -rdynamic -L/home/pierrick/files/projet-synthese/devlpt/devlpt/build ../../build/libTree_LIB.a ../../build/libPlayer_LIB.a ../../build/libSamplerManager_LIB.a ../../build/libMainWindow_LIB.a /usr/lib64/qt4/libQtGui.so -lpng -lSM -lICE -lXrender -lXrandr -lXcursor -lXfixes -lfreetype -lfontconfig -lXext -lX11 -lm /usr/lib64/qt4/libQtCore.so /lib64/libz.so -lgthread-2.0 -lglib-2.0 -lrt -lpthread -ldl -Wl,-rpath,/home/pierrick/files/projet-synthese/devlpt/devlpt/build:/usr/lib64/qt4:/lib64
    ../../build/libMainWindow_LIB.a(mainwindow.cpp.o): In function `~MainWindow':
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:183: undefined reference to `vtable for MainWindow'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:183: undefined reference to `vtable for MainWindow'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:183: undefined reference to `vtable for MainWindow'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:183: undefined reference to `vtable for MainWindow'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:183: undefined reference to `vtable for MainWindow'
    ../../build/libMainWindow_LIB.a(mainwindow.cpp.o):/home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:183: more undefined references to `vtable for MainWindow' follow
    ../../build/libMainWindow_LIB.a(mainwindow.cpp.o): In function `MainWindow':
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:127: undefined reference to `Arborescence::Arborescence(QString, QWidget*)'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:130: undefined reference to `SamplerManager::SamplerManager(QString, QWidget*)'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:133: undefined reference to `Player:layer(QString, QWidget*)'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:3: undefined reference to `vtable for MainWindow'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:3: undefined reference to `vtable for MainWindow'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:127: undefined reference to `Arborescence::Arborescence(QString, QWidget*)'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:130: undefined reference to `SamplerManager::SamplerManager(QString, QWidget*)'
    /home/pierrick/files/projet-synthese/devlpt/devlpt/mainwindow/mainwindow.cpp:133: undefined reference to `Player:layer(QString, QWidget*)'
    collect2: ld returned 1 exit status
    make[2]: *** [../bin/executable] Error 1
    make[2]: Leaving directory `/home/pierrick/files/projet-synthese/devlpt/devlpt/compilation'
    make[1]: *** [test/CMakeFiles/executable.dir/all] Error 2
    make[1]: Leaving directory `/home/pierrick/files/projet-synthese/devlpt/devlpt/compilation'
    make: *** [all] Error 2
    Désolé pour ce message assez long mais au moins je pense avoir donne toutes les informations.

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 25
    Points : 14
    Points
    14
    Par défaut
    Salut,

    J'ai eu le meme probleme.
    En fait, si tu n'arrives pas à créer les fichiers moc avec Cmake (arrétez moi mais je crois que c'est possible), tu peux les créer à la main et les rajouter à tes librairies.
    Par exemple, pour un répertoire où tu te trouves avec une classe comme tu as donné comme exemple :
    ADD_LIBRARY(Player_LIB
    player.h
    player.cpp
    )
    Tu fais (verifie que tu as moc sinon installe le)
    moc player.h -o moc_player.cpp
    Ce moc_player.cpp est dans le même répertoire que les player.*
    Ensuite, dans le CMakeLists, tu fais
    ADD_LIBRARY(Player_LIB
    player.h
    player.cpp
    moc_player.cpp
    )

    Voila

  3. #3
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 92
    Points : 116
    Points
    116
    Par défaut
    D'accord, je vais essayer ca. Mais, je dois exclusivement utiliser cmake.
    Je n'ai "pas le droit" d'utiliser moc. Il faut que tout se passe a partir de cmake.

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 25
    Points : 14
    Points
    14
    Par défaut
    Ok.
    Pourtant, tes .h et .cpp ne sont pas créés avec CMake. La c'est pareil, tu les créé à coté.
    CMake servira a compiler, et tes nouveaux .h feront partis de la source, non?

  5. #5
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 92
    Points : 116
    Points
    116
    Par défaut
    Je n'ai pu généré qu'un seul fichier moc. Pour les autres fichiers j'avais ce message :
    player.h:0: Warning: No relevant classes found. No output generated.
    Ensuite j'ai inclu le fichier moc généré dans mon fichier .h

    J'ai essayé de recompiler, j'ai eu une erreur me disant que mon fichier .h n'avais pas "#include <QObject>". Je l'ai rajouté et régénéré un moc.

    Mais, dans le fichier moc généré, j'ai toujours une erreur me disant que le header n'inclu pas QObject.

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 25
    Points : 14
    Points
    14
    Par défaut
    Il faut que tu genere des fichiers moc que pour les fichiers qui te retourne une erreur.
    Essaie juste pour mainwindow.h et ensuite recompile pour voir si tu as toujours des erreurs.

  7. #7
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 92
    Points : 116
    Points
    116
    Par défaut
    J'ai généré les moc qu'il fallait. J'avais toujours des erreurs.
    J'ai fini par trouver : c'est dans le CMakeLists.txt ou se trouve le main. L'ordre des librairies mise dans la variable "TARGET_LINK_LIBRARIES" a un sens !!

    Il fallait que je mette "MainWindow_LIB" en seconde place en partant de la gauche.

    Ca n'a pas résolu la totalité de mes problèmes avec CMake, mais j'y vois un peu plus claire maintenant.

Discussions similaires

  1. compiler projet OpenGl with Cmake ou codeBlocks
    Par SuperPhenix dans le forum Systèmes de compilation
    Réponses: 0
    Dernier message: 27/12/2014, 19h34
  2. [Cmake] Compiler en projet en plusieurs langages
    Par ManusDei dans le forum Systèmes de compilation
    Réponses: 3
    Dernier message: 13/02/2011, 15h17
  3. [IDE][VS2005] Comment compiler projet et obtenir un exe ?
    Par Bing dans le forum Visual Studio
    Réponses: 18
    Dernier message: 07/11/2008, 21h15
  4. compilation projet ( en plusieur fichier )
    Par damien77 dans le forum Code::Blocks
    Réponses: 3
    Dernier message: 21/02/2007, 23h46
  5. [1.1] Comment compiler projet en ligne de commande ?
    Par joujoukinder dans le forum Framework .NET
    Réponses: 3
    Dernier message: 20/01/2006, 13h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo