Difference between HEADERS and INCLUDEPATH
-
If I add a bunch of headers that are not in the project directory, they all show up in the .pro file as
HEADERS += header1.h \ header2.h \ ...
however when I try to build I get a compiler error saying it can't find the headers. Looking in the Compile output it looks like the g++ command that is issued doesn't -I include the directories the header files are in. It appears that I need to add a INCLUDEPATH variable in the .pro file to specify where those files are located. Why? This seems redundant since the paths to those files are specific in the HEADERS variable. i.e. my project file is like this:
TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt SOURCES += \ ../common/comms/src/serial_port.cpp \ ../common/comms/src/tcp_port.cpp \ ../common/comms/src/udp_port.cpp INCLUDEPATH += \ # <- include \ # <- Without these 3 lines the compile fails ../common/comms/include # <- HEADERS += \ ../common/comms/include/connection.h \ # which just seems weird since paths are given here ../common/comms/include/ConnectionBuilder.h \ ../common/comms/include/serial_port.h \ ../common/comms/include/tcp_port.h \ ../common/comms/include/udp_port.h \
-
Hi and welcome to devnet,
The INCLUDEPATH directive is to tell the compiler where to look for when a header is included by one of your cpp file.
HEADERS contains a list of headers that are part of your project and that moc might be run on.
-
Is there by chance then a way when adding files (using the Add Existing Directory) to a project to include it both in HEADERS and INCLUDEPATH (instead of just the HEADERS section)?
-
AFAIK, no.
However I'd recommend to rather have a
comms.pri
file that you include in your application .pro file that will do that.