Confused with QtCreator build process



  • Hello,
    I am trying to reuse update and further develop my two dear old C++ projects (initiated in 2011) named Mathlib and Phygenic (Phygenic calls Mathlib classes and global functions). More recently, I created two new projects Mathlib2 and Phygeniclib as static libraries (and old projects have been deleted). QtCreator generated for me two nice library files: libMathlib2.a and libPhygenicLib.a (actually 2 times 2 because I compiled with both Debug and Release kits, just to be on the same side...).
    These libraries should be exploited by either the console-based project Phygenic_test or the Qwidget-based project PG_Qt .
    Everything builds and runs as expected with Phygenic_test , however it won't build with PG_Qt while both are expected to do the same.
    Here is the successful Phygenic_test project (using Debug kit) :

    QT += core
    QT -= gui
    CONFIG += c++11
    TARGET = Phygenic_test
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    LIBS += d:/Qt-apps/build-Mathlib2-Desktop_Qt_5_5_1_MinGW_32bit-Debug/debug/libMathlib2.a \
            d:/Qt-apps/build-PhygenicLib-Desktop_Qt_5_5_1_MinGW_32bit-Debug/debug/libPhygenicLib.a
    INCLUDEPATH += d:/Qt-apps/PhygenicLib \
                                      d:/Qt-apps/Mathlib2
    SOURCES += main.cpp
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    

    I am not sure to understand the definition of QT_DEPRECATED WARNINGS ; I just hope it won't impact my projects...
    My main function is as follows:

     #include <QCoreApplication>
    #include <iostream>
    #include <cmath>
    #include <fstream>
    #include <stdexcept>
    #include "xploit_pg.h"
    
    using namespace std;
    ofstream fdmp("test.dmp");
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
    try { 
    int choice= 5 ;
    switch (choice) {
        case 5: { // test compatibility Qapplication, Qcore, etc
    
               Phygenic* ptr_modele_brut= new Phygenic ;
               ptr_modele_brut->trace(fdmp);
               delete ptr_modele_brut ;
    
               Phygenic modele_brut= Phygenic() ;
               modele_brut.trace(fdmp);
    
               fdmp<<"All OK! \n" ;
               break;
            } // end test compatibility Qapplication, Qcore, etc
        case n {  // some other tests
                  (...)
           } // end case n
       } // end switch
    } catch (string err) { fdmp << err << endl ; }  // actually no throw called, hence useless
       cout<<'\a' ; // ring the bell
       fdmp << "--- END EXECUTION --- "<< std::endl;
       fdmp.close() ;
      return a.exec();
    }
    

    Note that header xploit_pg.h can be found in INCLUDEPATH += d:/Qt-apps/PhygenicLib . xploit_pg.h includes other includes which include further includes with all prototypes necessary to declare a Phygenic object and anything else needed including Mathlib2 classes and functions.

    Now the failed PG_Qt project:

    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = PG_Qt
    TEMPLATE = app
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    LIBS += d:/Qt-apps/build-Mathlib2-Desktop_Qt_5_5_1_MinGW_32bit-Debug/debug/libMathlib2.a \
            d:/Qt-apps/build-PhygenicLib-Desktop_Qt_5_5_1_MinGW_32bit-Debug/debug/libPhygenicLib.a
    INCLUDEPATH += d:/Qt-apps/PhygenicLib \
                   d:/Qt-apps/Mathlib2
    
    SOURCES += main.cpp\
            pg_qt_mainwindow.cpp
    HEADERS  += pg_qt_mainwindow.h
    FORMS    += pg_qt_mainwindow.ui
    

    And the mainwindow.cpp which is hosting the Phygenic stuff:

    #include "pg_qt_mainwindow.h"
    #include "ui_pg_qt_mainwindow.h"
    #include <QFileDialog>
    #include <QFile>
    #include <QMessageBox>
    #include "xploit_pg.h"
    
    PG_Qt_MainWindow::PG_Qt_MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::PG_Qt_MainWindow)
    {
        ui->setupUi(this);
    
        ofstream fdmp("test.dmp");
    
        Phygenic* ptr_modele_brut= new Phygenic ;
        ptr_modele_brut->trace(fdmp);
        delete ptr_modele_brut ;
    
        Phygenic modele_brut= Phygenic() ;
        modele_brut.trace(fdmp);
    
        fdmp<<"Why doesn't it work in this context? \n" ;
    }
    
    PG_Qt_MainWindow::~PG_Qt_MainWindow()
    {
        delete ui;
    }
    
    void PG_Qt_MainWindow::on_actionQuitter_triggered()
    {
        ui->statusBar->showMessage("Quitter application PG_Qt... Bye!") ; 
        QCoreApplication::quit();
    }
    
    void PG_Qt_MainWindow::on_actionOuvrir_triggered()
    {   
    return ; // not yet developped
    }
    
    

    I don't understand why this does not compile & build... the problem message sounds senseless to me:

    D:\Qt-apps\PhygenicLib\mecagen.cpp:173: erreur : undefined reference to `Prod_Mat3x3(Mat3x3, Mat3x3)
    D:\Qt-apps\PhygenicLib\mecagen.cpp:176: erreur : undefined reference to `Prod_V3(V3, V3)
    etc, etc...
    

    It looks like the build process is trying to compile again the mecagen.cpp source whilst this is supposed to be already compiled in the file libPhygenicLib.a . (right?). Furthermore, reference to Mathlib2 functions are metioned missing whilst they are supposedly available in libMathlib2.a . (?)
    I am not at all familiar with the compile/build process in C++ (a short experience with Borland JavaBuilder some 20 years ago, and this was real easy and carefree!). make, Qmake, makefile, build kits are just buzz words to me... ! Not to mention the deep mysteries of Qtcreator QtApplication, QtWidgets. Where can I find some SIMPLE examples (for MS Window desktop, preferably) and books on these subjects? Examples provided with QtCreator 5.8.0 are very much focused on UI and multimedia stuff and mainly targetting Android or iOs on mobile and tablets, not desktops, and are not for C++/Qt beginners.
    Thanks for any help!


  • Lifetime Qt Champion

    Hi,

    Are all these projects independent ? Or are you using the SUBDIRS template ?



  • @SGaist
    No SUBDIRS since i don't fully understand the concept of SUBDIRS.
    Basically, I have different applications that should use the functions and classes from libraries Mathlib2 and PhygenicLib. PhygenicLib itself needs Mahlib2.


  • Lifetime Qt Champion

    The subdirs projects are usually a collection of libraries and applications that form a project. Each one is a separate project while being part of the global project. e.g. the Qt Framework is a very big subdirs project

    Are you using Qt Creator to build your projects ?.



  • @SGaist
    Yes, I am using Qt Creator 4.2.1 Basé sur Qt 5.8.0 (MSVC 2015, 32 bit).
    As my libraries (esp. Mathlib2) are qutie generic and meant to be shared between numerous distinct projects, I would rather avoid to have them inserted in a specific project. I realized that shared libraries (DDL's) are probably better fit to that purpose than static libraries, but step by step...


  • Lifetime Qt Champion

    Static VS Dynamic is another debate.

    Currently the most important point is why do you have files unrelated to your projects that are built.

    I currently can't see anything wrong the snippets you provide related to that problem.

    One thing you can do is to start a new project, link against your custom libraries. If that works then step by step, add the files from your current failing project until it either builds properly or fails again, then you should have a starting point to see what's wrong.


Log in to reply