Solved qmake - Precompile
-
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:
- precompile the .sqC file
- 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 -
Hi,
Have you added the output from your precompilation step (the object files) to theOBJECTS
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. -
Hi and welcome to devnet,
To add to @kshegunov, can you share your .pro file ? That would give more information about what is happening.
-
@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 -
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.
-
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 aclang
QMAKESPEC
for ag++
compilation you specify the debug information and the std version as compiler flags when you should useCONFIG
for that.
If you don't want Qt (QT -= core gui
), then useCONFIG -= qt
. You add system include paths when they are already in thePATH
. -
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 triedDB2CONN.commands = db2 connect to yourpart QMAKE_EXTRA_TARGETS += DB2CONN
(and also to add it as another extra_compiler) but it wasn't working :(
-
@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:
-
Remove the QMAKESPEC, that is to be specified in another way:
a) From the command line if you're usingqmake
that way
b) QtCreator will set it up for you whenever you change the compiler in the UI -
Remove
QMAKE_CXXFLAGS
, useCONFIG += debug
(to get-g -Wno-narrowing
) andCONFIG += c++14
to get-std=c++14
. -
Remove
QT -= core gui
, useCONFIG -= qt
to remove Qt dependency -
Remove:
INCLUDEPATH += /usr/include/qt5
andINCLUDEPATH += /usr/local/include
, those are already set up for you. -
If you need to change to a newer gcc/g++ version, then there's a better way to do that
QMAKE_CC = g++-7
andQMAKE_CXX = g++-7
will work but it's not their place to be in the.pro
file. -
QMAKE_LIBDIR += /usr/local/lib64
is not needed, remove it. -
QMAKE_LIBDIR += /opt/ibm/db2/V11.1/lib64
is wrong. UseLIBS += -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.
-
-
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!