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. qmake - Precompile
Forum Updated to NodeBB v4.3 + New Features

qmake - Precompile

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
9 Posts 3 Posters 3.0k Views 2 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.
  • T Offline
    T Offline
    tsschulz
    wrote on last edited by
    #1

    Hi,

    I need a precompile step. The reason is that I have a project with DB2 inline sql code. So I have file, i.e. example.sqC. That files needs to be precompiled with db2 first: db2 prep example.sqC bindfile
    This will create the example.C file which I can compile normally then.

    So what I'll do is:

    1. precompile the .sqC file
    2. compile the generated .C file with the other files of the project
      (3. link all together)

    I tried it with QMAKE_EXTRA_COMPILERS and QMAKE_EXTRA_TARGETS. With the extra compilers, I got it to pre compile. But then it wasn't compiled with the "normal" tools, and also my INCLUDEPATH was ignored. And it wasn't linked into the .so file.
    With extra targets, nothing happend.

    Greetings
    Torsten

    kshegunovK 1 Reply Last reply
    0
    • T tsschulz

      Hi,

      I need a precompile step. The reason is that I have a project with DB2 inline sql code. So I have file, i.e. example.sqC. That files needs to be precompiled with db2 first: db2 prep example.sqC bindfile
      This will create the example.C file which I can compile normally then.

      So what I'll do is:

      1. precompile the .sqC file
      2. compile the generated .C file with the other files of the project
        (3. link all together)

      I tried it with QMAKE_EXTRA_COMPILERS and QMAKE_EXTRA_TARGETS. With the extra compilers, I got it to pre compile. But then it wasn't compiled with the "normal" tools, and also my INCLUDEPATH was ignored. And it wasn't linked into the .so file.
      With extra targets, nothing happend.

      Greetings
      Torsten

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Hi,
      Have you added the output from your precompilation step (the object files) to the OBJECTS variable? This'd be required so it's added as a dependency entry in the makefile and linked alongside the other code. I'll try to find you an example, but it'd may take some time.

      Read and abide by the Qt Code of Conduct

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

        Hi and welcome to devnet,

        To add to @kshegunov, can you share your .pro file ? That would give more information about what is happening.

        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
        1
        • T Offline
          T Offline
          tsschulz
          wrote on last edited by
          #4

          @SGaist said in qmake - Precompile:

          Hi and welcome to devnet,

          To add to @kshegunov, can you share your .pro file ? That would give more information about what is happening.

          Of course. Sorry that I forgot it.

          #-------------------------------------------------
          #
          # Project created by QtCreator 2015-12-11T09:17:05
          #
          #-------------------------------------------------
          
          QMAKE_CXXFLAGS += -std=c++14 -g -Wno-narrowing
          QMAKESPEC = /usr/lib64/qt5/mkspecs/linux-clang-libc++/
          
          QT       -= core gui
          
          TARGET = YpDb
          TEMPLATE = lib
          
          DEFINES += YPDB_LIBRARY
          
          SQC.target = ${QMAKE_FILE_BASE}.cpp
          SQC.commands = db2 connect to yourpart && db2 PREP ${QMAKE_FILE_NAME} bindfile && mv ${QMAKE_FILE_BASE}.C ${QMAKE_FILE_BASE}.cpp
          SQC.depends = FORCE
          SQC.input += FAKEINPUTS
          PRE_TARGETDEPS += FAKEINPUTS
          QMAKE_EXTRA_COMPILER += SQC 
          
          #FAKEINPUTS += dbrights.sqC
          
          SOURCES += db.cpp \
              dbbase.cpp \
              dbgamebase.cpp \
              dbcommunity.cpp \
              dbrights.cpp \
              dbsocial.cpp \
          
          HEADERS += db.h\
                  ypdb_global.h \
              dbbase.h \
              dbgamebase.h \
              dbcommunity.h \
              dbrights.h \
              dbsocial.h \
          
          LIBS += -lypconfig \
              -ldb2 \
              -lYpHelper \
          
          unix {
              INCLUDEPATH += /usr/include/qt5
              INCLUDEPATH += /usr/local/include
              INCLUDEPATH += /opt/ibm/db2/V11.1/include
              INSTALLS += target
              QMAKE_CC = g++-7
              QMAKE_CXX = g++-7
              QMAKE_LIBDIR += /opt/ibm/db2/V11.1/lib64
              QMAKE_LIBDIR += /usr/local/lib64
          }
          
          target.path = /usr/local/lib64
          
          headers.path = /usr/local/include/Yp
          headers.files += $${HEADERS}
          
          INSTALLS += target \
              headers
          

          As you can see, I don't only use more include and lib pathes, I also need another compiler, because the one that is standard at my linux distribution is too old for some libs I use.

          Greetings
          Torsten

          1 Reply Last reply
          0
          • kshegunovK kshegunov

            Hi,
            Have you added the output from your precompilation step (the object files) to the OBJECTS variable? This'd be required so it's added as a dependency entry in the makefile and linked alongside the other code. I'll try to find you an example, but it'd may take some time.

            T Offline
            T Offline
            tsschulz
            wrote on last edited by
            #5

            Hi,

            @kshegunov I thought about and and it could help me really - if a) the right compiler would be used and b) the INCLUDEPATH would be used.

            kshegunovK 1 Reply Last reply
            0
            • T tsschulz

              Hi,

              @kshegunov I thought about and and it could help me really - if a) the right compiler would be used and b) the INCLUDEPATH would be used.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              Couldn't find my experiments from before, but this should work for you I think (or it should be close at least):

              SQC.input = FAKEINPUTS
              SQC.output = ${QMAKE_FILE_BASE}.cpp
              SQC.commands = db2 connect to yourpart && db2 PREP ${QMAKE_FILE_NAME} bindfile && mv ${QMAKE_FILE_BASE}.C ${QMAKE_FILE_BASE}.cpp
              SQC.CONFIG += target_predeps
              SQC.variable_out = SOURCES
              
              QMAKE_EXTRA_COMPILER += SQC 
              

              By the way you have too much stuff whose place is not in the .pro file, e.g. you force a clang QMAKESPEC for a g++ compilation you specify the debug information and the std version as compiler flags when you should use CONFIG for that.
              If you don't want Qt (QT -= core gui), then use CONFIG -= qt. You add system include paths when they are already in the PATH.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              1
              • T Offline
                T Offline
                tsschulz
                wrote on last edited by
                #7

                Hey, thanks!

                With that help I was able to get it running. The block I need is this:

                SQC.output = ${QMAKE_FILE_BASE}.cpp
                SQC.target = ${QMAKE_FILE_BASE}.cpp
                SQC.commands = db2 connect to yourpart && db2 PREP ${QMAKE_FILE_NAME} bindfile && mv ${QMAKE_FILE_BASE}.C ${QMAKE_FILE_BASE}.cpp
                SQC.depends = FORCE
                SQC.input += FAKEINPUTS
                SQC.CONFIG += target_predeps
                SQC.variable_out = SOURCES
                QMAKE_EXTRA_COMPILERS += SQC 
                
                FAKEINPUTS += db.sqC
                

                (only for if someone search for how to fix this.

                What you said too... Well, you're right. The CONFIG -= qt hadn't work in one project, but I think that was an error of code and not by qmake.
                The include pathes are historical. I don't know why, but I had to add the system pathes that the self created headers were found.
                And also the clang definiton is historical. I was using clang for longer, and I think when everything is working, I'll switch back to it.

                One last question:
                Can I let the "db2 connect..." be executed as first command? Because I don't need it for every file. I tried

                DB2CONN.commands = db2 connect to yourpart
                QMAKE_EXTRA_TARGETS += DB2CONN
                

                (and also to add it as another extra_compiler) but it wasn't working :(

                kshegunovK 1 Reply Last reply
                0
                • T tsschulz

                  Hey, thanks!

                  With that help I was able to get it running. The block I need is this:

                  SQC.output = ${QMAKE_FILE_BASE}.cpp
                  SQC.target = ${QMAKE_FILE_BASE}.cpp
                  SQC.commands = db2 connect to yourpart && db2 PREP ${QMAKE_FILE_NAME} bindfile && mv ${QMAKE_FILE_BASE}.C ${QMAKE_FILE_BASE}.cpp
                  SQC.depends = FORCE
                  SQC.input += FAKEINPUTS
                  SQC.CONFIG += target_predeps
                  SQC.variable_out = SOURCES
                  QMAKE_EXTRA_COMPILERS += SQC 
                  
                  FAKEINPUTS += db.sqC
                  

                  (only for if someone search for how to fix this.

                  What you said too... Well, you're right. The CONFIG -= qt hadn't work in one project, but I think that was an error of code and not by qmake.
                  The include pathes are historical. I don't know why, but I had to add the system pathes that the self created headers were found.
                  And also the clang definiton is historical. I was using clang for longer, and I think when everything is working, I'll switch back to it.

                  One last question:
                  Can I let the "db2 connect..." be executed as first command? Because I don't need it for every file. I tried

                  DB2CONN.commands = db2 connect to yourpart
                  QMAKE_EXTRA_TARGETS += DB2CONN
                  

                  (and also to add it as another extra_compiler) but it wasn't working :(

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #8

                  @tsschulz said in qmake - Precompile:

                  DB2CONN.commands = db2 connect to yourpart
                  QMAKE_EXTRA_TARGETS += DB2CONN
                  

                  Looks correct, but you ought to also specify that target to be executed in the proper order. Try adding something like this:

                  # Create a target to be executed before the build
                  DB2CONN.commands = db2 connect to yourpart
                  QMAKE_EXTRA_TARGETS += DB2CONN
                  
                  PRE_TARGETDEPS += DB2CONN
                  
                  # Add a custom compilation step before the regular build
                  SQC.output = ${QMAKE_FILE_BASE}.cpp
                  // ...
                  SQC.depends = DB2CONN #<< Change here
                  // ...
                  QMAKE_EXTRA_COMPILERS += SQC
                  

                  As for your superfluous lines in the pro:

                  1. Remove the QMAKESPEC, that is to be specified in another way:
                    a) From the command line if you're using qmake that way
                    b) QtCreator will set it up for you whenever you change the compiler in the UI

                  2. Remove QMAKE_CXXFLAGS, use CONFIG += debug (to get -g -Wno-narrowing) and CONFIG += c++14 to get -std=c++14.

                  3. Remove QT -= core gui, use CONFIG -= qt to remove Qt dependency

                  4. Remove: INCLUDEPATH += /usr/include/qt5 and INCLUDEPATH += /usr/local/include, those are already set up for you.

                  5. If you need to change to a newer gcc/g++ version, then there's a better way to do that QMAKE_CC = g++-7 and QMAKE_CXX = g++-7 will work but it's not their place to be in the .pro file.

                  6. QMAKE_LIBDIR += /usr/local/lib64 is not needed, remove it.

                  7. QMAKE_LIBDIR += /opt/ibm/db2/V11.1/lib64 is wrong. Use LIBS += -L/opt/ibm/db2/V11.1/lib64 -ldb2 when you specify the dependent libraries.

                  PS. You may also want to read this document about qmake.

                  Read and abide by the Qt Code of Conduct

                  T 1 Reply Last reply
                  2
                  • kshegunovK kshegunov

                    @tsschulz said in qmake - Precompile:

                    DB2CONN.commands = db2 connect to yourpart
                    QMAKE_EXTRA_TARGETS += DB2CONN
                    

                    Looks correct, but you ought to also specify that target to be executed in the proper order. Try adding something like this:

                    # Create a target to be executed before the build
                    DB2CONN.commands = db2 connect to yourpart
                    QMAKE_EXTRA_TARGETS += DB2CONN
                    
                    PRE_TARGETDEPS += DB2CONN
                    
                    # Add a custom compilation step before the regular build
                    SQC.output = ${QMAKE_FILE_BASE}.cpp
                    // ...
                    SQC.depends = DB2CONN #<< Change here
                    // ...
                    QMAKE_EXTRA_COMPILERS += SQC
                    

                    As for your superfluous lines in the pro:

                    1. Remove the QMAKESPEC, that is to be specified in another way:
                      a) From the command line if you're using qmake that way
                      b) QtCreator will set it up for you whenever you change the compiler in the UI

                    2. Remove QMAKE_CXXFLAGS, use CONFIG += debug (to get -g -Wno-narrowing) and CONFIG += c++14 to get -std=c++14.

                    3. Remove QT -= core gui, use CONFIG -= qt to remove Qt dependency

                    4. Remove: INCLUDEPATH += /usr/include/qt5 and INCLUDEPATH += /usr/local/include, those are already set up for you.

                    5. If you need to change to a newer gcc/g++ version, then there's a better way to do that QMAKE_CC = g++-7 and QMAKE_CXX = g++-7 will work but it's not their place to be in the .pro file.

                    6. QMAKE_LIBDIR += /usr/local/lib64 is not needed, remove it.

                    7. QMAKE_LIBDIR += /opt/ibm/db2/V11.1/lib64 is wrong. Use LIBS += -L/opt/ibm/db2/V11.1/lib64 -ldb2 when you specify the dependent libraries.

                    PS. You may also want to read this document about qmake.

                    T Offline
                    T Offline
                    tsschulz
                    wrote on last edited by
                    #9

                    @kshegunov

                    Thanks for your help. Most I did like you said. Only I had to add the -Wno-narrowing, because debug didn't add it. And it is needed for the precompiled files from db2.

                    The compiler options I didn't change, even that I know that there are other ways. In this case I prefer to set it with the .pro file.

                    Thank you!

                    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