How do I set include directories and link libraries in qmake for C++?

To set include directories and link libraries in qmake for a C++ project, you will need to modify your .pro file. This file contains the project configuration settings for qmake. Below are examples demonstrating how to set these properties.

Setting Include Directories

To include additional directories for header files, you can use the INCLUDEPATH variable:


# Add the path to the include directory
INCLUDEPATH += /path/to/your/include
    

Linking Libraries

To link against specific libraries, you will use the LIBS variable:


# Link against a specific library
LIBS += -L/path/to/your/lib -lyourlibrary
    

Complete Example

Here is a complete example of a .pro file that includes both include directories and library linking:


TEMPLATE = app
TARGET = myapp
CONFIG += console
CONFIG -= app_bundle

# Specify include directories
INCLUDEPATH += /usr/include/myproject
INCLUDEPATH += /usr/local/include

# Specify libraries to link
LIBS += -L/usr/lib/myproject -lmylib
LIBS += -lotherlib

SOURCES += main.cpp
    

qmake C++ include directories link libraries .pro file project configuration