QT Creator: build vs qmake
-
I have a problem with building my program using qt creator. I got a .pro file which works with qmake. I.e. I type qmake, then make - everything is compiled.
Now I open a qt creator project with the same .pro file, try to build it, it says: TCanvas.h: No such file or directory.
I can also run qmake from qtcreator - it works, but build doesn't work.
I'm on linux Mint 17.1, Qt Creator 3.0.1, Qt version 4.8.6 for Desktop.
Here is my .pro file:
TEMPLATE = app win32 { QMAKE_CXXFLAGS += -FIw32pragma.h } CONFIG += qt warn_on thread INCLUDEPATH += $(ROOTSYS)/include win32:LIBS += -L$(ROOTSYS)/lib -llibCore -llibCint -llibRIO -llibNet \ -llibHist -llibGraf -llibGraf3d -llibGpad -llibTree \ -llibRint -llibPostscript -llibMatrix -llibPhysics \ -llibGui -llibRGL else:LIBS += -L$(ROOTSYS)/lib -lCore -lCint -lRIO -lNet \ -lHist -lGraf -lGraf3d -lGpad -lTree \ -lRint -lPostscript -lMatrix -lPhysics \ -lGui -lRGL HEADERS += canvas.h SOURCES += canvas.cxx main.cxx
-
@yur70
Is the qmake that QtCreator uses the same as the one you use from the command line? Have you installed all the needed-dev
packages (if any)?-L$(ROOTSYS)/lib
What is
ROOTSYS
and why do you need to use it, is it set correctly? -
@kshegunov said:
What is
ROOTSYS
and why do you need to use it, is it set correctly?ROOT is a very powerfull statistical data analysis framework, initially developped for Particle Physics (ROOT website). The traditional way to use ROOT once compiled is to define the ROOTSYS environment variable and not add the binaries in the path (why, I don't know...).
-
As @kshegunov already asked: are you sure you're using the same qmake in QtCreator?
Where and how do you set ROOTSYS environment variable?
You can set this variable in QtCreator in project settings under "Build Environment".
And in the compiler output you can check whether al paths are really passed to the compiler. -
@kshegunov said:
@yur70
Is the qmake that QtCreator uses the same as the one you use from the command line? Have you installed all the needed-dev
packages (if any)?-L$(ROOTSYS)/lib
What is
ROOTSYS
and why do you need to use it, is it set correctly?I believe that qmake is always the same. I can go to the build-Desktop-Debug folder (which is created by the qtcreator) and run qmake + make from there, it all works. But the "build" command from qtcreator doesn't.
ROOTSYS is sen correctly. I can replace it by the full path to the libraries (/cern/root), but the result is the same.
-
@jsulm said:
As @kshegunov already asked: are you sure you're using the same qmake in QtCreator?
Where and how do you set ROOTSYS environment variable?
You can set this variable in QtCreator in project settings under "Build Environment".
And in the compiler output you can check whether al paths are really passed to the compiler.It doesn't matter if qmake is the same or not. With qmake it always works: I can run qmake from the command line, and also use "Run qmake" from qtcreator (by right clicking on the project). So qmake (or "Run qmake") - works, build - doesn't work.
-
@yur70 What about my other question regarding ROOTSYS?
I think, in QtCreator Projects/Build Environment it is not set, so thisINCLUDEPATH += $(ROOTSYS)/include
expands to /include, so TCanvas.h is not found (I assume it is part of ROOT, right?).
You can easily check that looking at the compiler output (you can see there which pats are passed to the compiler, look for -I...). -
@JohanSolo
Being a nuclear physicist myself I know what ROOT is, what I didn't know is how it's set up, as I haven't used it. SinceROOTSYS
is simply a variable I didn't deduce that it's one defined for/used by CERN's ROOT. Thanks for the explanation though!With qmake it always works: I can run qmake from the command line, and also use "Run qmake" from qtcreator (by right clicking on the project). So qmake (or "Run qmake") - works, build - doesn't work.
qmake is an intermediate step before building. It takes a .pro (project) file and generates an ordinary Makefile from that. What it doesn't do is check the flags you pass to the compiler/linker or paths. That's why the question "Are all paths correct during the build step?" is relevant. So, could you please post the whole build line with all the compiler switches, and not only the error you get?
-
@yur70 Because qmake only does a syntax check and generates a Makefile and Moc files (and probably some other tasks unrelated to your paths). It is the build steps that requires the include paths to be correct. That is why I suggested looking at the compile output and verifying the paths there.
-
I think, in QtCreator Projects/Build Environment it is not set, so this
INCLUDEPATH += $(ROOTSYS)/include
expands to /includeThe expansion happens in the Makefile's processing, if such is required when qmake is run the double dollar variable reference is required, i.e.:
INCLUDEPATH += $$(ROOTSYS)/include
(Posting this only for completeness)
-
@kshegunov Wherever the expansion happens if ROOTSYS is not set the resulting path will be invalid.
We really need the complete build log to check this. -
Thanks for your help, guys. The problem seems to be indeed in the environment variable. I set ROOTSYS in the Projects/Build Environment, now it finds the headers, but I get the following error:
:-1: warning: libMathCore.so, needed by /cern/root/lib/libHist.so, not found (try using -rpath or -rpath-link)
.. and then a lot of errors with undefined reference.
Where and how should I insert "-rpath"?
-
Where and how should I insert "-rpath"?
For development you shouldn't. Make sure you have the required binary in the linker search path. You need to have
libMathCore.so
in the$(ROOTSYS)/lib
directory. If you need to add additional path for the linker add another-L
switch to theLIBS
variable in your project file:LIBS += -L/another/path/to/search/for/so/files
If you're not building the
libHist.so
yourself, then provide additional linker paths by appendingLD_LIBRARY_PATH
(again, this is for development). -
@yur70 said:
:-1: warning: libMathCore.so, needed by /cern/root/lib/libHist.so, not found (try using -rpath or -rpath-link)
The
libMathCore.so
should be in your/cern/root/lib/
directory as well (it's a ROOT lib as well). You should check your ROOT installation. I guess you compiled it yourself (otherwise no need for ROOTSYS to be defined). -
Finally, I found the reason. I had to add -Wl,-rpath,$(ROOTSYS)/lib to the end of the LIBS definition. So the solution is the following:
- Add ROOTSYS to the Projects/Build Environment
- Add -Wl,-rpath,$(ROOTSYS)/lib to the libs.
The .pro file looks like this:
TEMPLATE = app win32 { QMAKE_CXXFLAGS += -FIw32pragma.h } CONFIG += qt warn_on thread INCLUDEPATH += $(ROOTSYS)/include win32:LIBS += -L$(ROOTSYS)/lib -llibCore -llibCint -llibRIO -llibNet \ -llibHist -llibGraf -llibGraf3d -llibGpad -llibTree \ -llibRint -llibPostscript -llibMatrix -llibPhysics \ -llibGui -llibRGL else:LIBS += -L$(ROOTSYS)/lib -lCore -lCint -lRIO -lNet \ -lHist -lGraf -lGraf3d -lGpad -lTree \ -lRint -lPostscript -lMatrix -lPhysics \ -lGui -lRGL -Wl,-rpath,$(ROOTSYS)/lib HEADERS += canvas.h SOURCES += canvas.cxx main.cxx