Question

Is there a way to include different libraries depending on the operating system with Qt-Creator?

In other words, is there an equivalent for the following lines in the .pro file:

#ifdef Q_WS_WIN
include(C:/myProject/myLybrary/my-lib.pri)
#endif

#ifdef Q_WS_X11
include(/home/user/myProject/myLybrary/my-lib.pri)
#endif

I know that the character '#' identifies a comment in the .pro file. What's the alternative here?

Was it helpful?

Solution 4

Have you tried this:

unix: include(/home/user/myProject/myLybrary/my-lib.pri)
win32: include(C:/myProject/myLybrary/my-lib.pri)

OTHER TIPS

You can also use it like that (if more than one file):

linux-g++ | linux-g++-64 | linux-g++-32 {
 # your includes
}

win32 {
 # your includes
}

Or if you like cross compile:

linux-g++-64{
# your includes
}

linux-arm-g++{
    # your includes
}

I believe by operating system that you mean the target architecture you are compiling for. That's the context in which the .pro file operates, and it may or may not be the same architecture as the operating system of the host machine you are developing on.

You can specify a conditional expression in the .pro file based on the qmake spec that you are compiling with. For example, if you want to include some libraries only when you are compiling for an embedded Linux architecture, then you would put:

linux-oe-g++ {
    LIBS += -lsomelib
    HEADERS += SomeClass.h
    SOURCES += SomeClass.cpp
}

These lines would only go into effect when linux-oe-g++ is used as the -spec argument for qmake. (This is set in the Qt Creator IDE by configuring the project to use a kit that has the platform specified in the "Qt makespec" field.)

A preprocessor directive like the following C++ code does depend on the operating system you are developing on:

#ifdef __linux__
#include "linux/mylinuxlib.h"
#endif

This conditional is environment-dependent and is true only if I am developing on a Linux OS. It does not depend on the target architecture I am compiling for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top