Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qmake takes sources from other directory than told to
MartinKT last edited by
Lets have the following file structure:
/lib |-- lib.pri |-- lib.cpp |-- lib.h /prj |-- prj.pro |-- /app |---- app.pro |---- app.cpp |-- /lib |---- lib.pri |---- lib.cpp |---- lib.h
The content of files is following:
TEMPLATE=app TARGET=app SOURCES += app.cpp include(../lib/lib.pri)
INCLUDEPATH += $$PWD DEPENDPATH += $$PWD SOURCES += $$PWD/lib.cpp HEADERS += $$PWD/lib.h
And files app.cpp, lib.cpp and lib.h are just some dummy app/ lib code.
When I run qmake/make in prj dir everything is ok.
But when I make release directory and run qmake/make as qtcreator does
mkdir release cd release qmake ../prj.pro make
in output appears:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../../app -I. -I../../lib -I../../../../tools/Qt5.5.0/5.5/gcc_64/include -I../../../../tools/Qt5.5.0/5.5/gcc_64/include/QtGui -I../../../../tools/Qt5.5.0/5.5/gcc_64/include/QtCore -I. -I../../../../tools/Qt5.5.0/5.5/gcc_64/mkspecs/linux-g++ -o app.o ../../app/app.cpp g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../../app -I. -I../../lib -I../../../../tools/Qt5.5.0/5.5/gcc_64/include -I../../../../tools/Qt5.5.0/5.5/gcc_64/include/QtGui -I../../../../tools/Qt5.5.0/5.5/gcc_64/include/QtCore -I. -I../../../../tools/Qt5.5.0/5.5/gcc_64/mkspecs/linux-g++ -o lib.o ../../../lib/lib.cpp
The problem is on the second line, where file
../../../lib/lib.cppis user for compilation instead of
When I remove lib directory from the highest level, qmake generates correct Makefile.
Is this qmakes behavior correct?
Is it my mistake?
Is there any way to avoid this?
Thank you, Martin
Hi and welcome to devnet,
You should rather avoid building inside your sources. It would be better to use a folder that's at the same level as your project dir.
If you still want to do that, you should use $ $PWD (without the space but since the forum is eating double dollars...) rather than .. for your include statement so it will use the full path rather than relative.
MartinKT last edited by MartinKT
thank you much for answer, but:
- building this way is the default QtCreator behavior now, isn't it?
- Good notice, I forgot to mention. When i use
include($$PWD/../lib/lib.pri), the result is the same (bad).
- No Qt Creator use shadow builds by default. If puts the shadow build folders at the same level as your sources.
- I would avoid having the same name reused (i.e. two lib.pri/lib.h/lib.cpp)