QT Creator: build vs qmake
-
@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