简体   繁体   中英

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, ie:

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

How to do that?

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM