Search code examples
c++qtqmakeinclude-path

qt, library -like project, and include <>


In Qt, I want to have a separate library-like project (not .lib, simple .cpp/.h files, but in separate project). Lets call it "library". Project which will include it call "test". To achieve this, in "library" project I create .pri file, instead of .pro. And from this moment I have the following file struct:

/library
   library.pri
   calc.h
   calc.cpp
/test
   test.pro
   main.cpp

The containment of library.pri is the following:

SOURCES += calc.cpp     
HEADERS += calc.h 

test.pro:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

#include(../library/library.pri)

SOURCES += main.cpp

Now I want to include calc.h . But I don't want to specify relative dir, i.e.:

#include "../library/calc.h", I want : #include <calc>

How to do that?


Solution

  • Put this into the library.pri project include file:

    SOURCES += calc.cpp     
    HEADERS += calc.h
    INCLUDEPATH += $$PWD # this is the extension!
    

    This addition ensures that any project file including this project include file gets the include path right for that library folder, not only "test".