Move header and source files to different location
-
Hi! I'm having an issue with restructuring my project. I would like to move the header files to a new folder named "include" and the source files to another one named "src". I have done it successfully for another project in the past, just by copy-pasting and adjusting the .pro file. However, I am not able to do it on this new project - the files are not properly recognized by Qt Creator. What steps am I missing here?
My .pro file looks like this at the moment:
TEMPLATE = lib CONFIG += dll DEFINES += MYNTERFACE_LIBRARY DESTDIR = $$PWD/lib/ !contains(DEFINES, _ENABLE_QT_GUI) { QT -= gui } # !contains(DEFINES, _ENABLE_QT_GUI) unix { target.path = /usr/lib } !isEmpty(target.path): INSTALLS += target contains(DEFINES, _STATIC_BUILD) { CONFIG -= dll CONFIG += staticlib } # contains(DEFINES, _STATIC_BUILD) CONFIG += c++11 # Compiler / Linker Options CONFIG(debug, debug|release) { TARGET = Mynterfaced } else { TARGET = MyInterface } # CONFIG(debug, debug|release) unix { target.path = /usr/lib } !isEmpty(target.path): INSTALLS += target HEADERS += \ MyInterface_global.h \ myinterface.h \ precompiled.h SOURCES += \ myinterface.cpp \
I would like the headers and sources to be located as follows:
HEADERS += \ include/MyInterface_global.h \ include/myinterface.h \ include/precompiled.h SOURCES += \ src/myinterface.cpp \
-
Hi,
That looks good.
What errors do you get ?
-
After moving the files and adjusting the .pro, the myinterface.cpp source can't find the included header. I am getting the following messages:
error: 'myinterface.h' file not found
error: use of undeclared identifier 'MyInterface'After changing the way I include the header in this source from:
#include "myinterface.h"
to:
#include "include/myinterface.h"
it works again. I find this strange, as previously in another project, I moved many files like this and didn't have an issue. Why is the "include/" path not recognized automatically? Am I missing somethin in the project?
-
@szumial said in Move header and source files to different location:
Why is the "include/" path not recognized automatically?
Because it's a non standard path.
@szumial said in Move header and source files to different location:
Am I missing somethin in the project?
Yes you are, you need to add that path to the INCLUDEPATH variable.
-
@szumial said in Move header and source files to different location:
I don't remember adding these non-standard paths in that previous project
Before, your header files and source files were located in the same directory. The preprocessor searches for header files in same directory, then in directories specified using -I parameter (that is what INCLUDEPATH adds) and then in system directories.