How to make the Qt project file (.pro) platform dependent?
Asked Answered
C

4

6

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?

Charentemaritime answered 26/4, 2013 at 7:58 Comment(1)
The very first page of the qmake tutorial shows you how: qt-project.org/doc/qt-4.8/qmake-tutorial.htmlJump
S
8

Have you tried this:

unix: include(/home/user/myProject/myLybrary/my-lib.pri)
win32: include(C:/myProject/myLybrary/my-lib.pri)
Sinistrodextral answered 26/4, 2013 at 8:29 Comment(0)
T
8

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
}
Tragopan answered 26/4, 2013 at 8:38 Comment(1)
You can use linux-g++* instead of linux-g++ | linux-g++-64...Armoire
S
3

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.

Spokeswoman answered 14/6, 2017 at 19:49 Comment(0)
N
1

Or if you like cross compile:

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

linux-arm-g++{
    # your includes
}
Natality answered 4/9, 2014 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.