Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Difference between HEADERS and INCLUDEPATH
QtWS25 Last Chance

Difference between HEADERS and INCLUDEPATH

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmake variables
4 Posts 2 Posters 18.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StrikeEagleIII
    wrote on last edited by
    #1

    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 \
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        StrikeEagleIII
        wrote on last edited by
        #3

        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)?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved