qtcreator subproject: multiple definition of main
I connect to the project (the target is an executable file) another project (also executable, that is, not a library) as a subproject. Here is a fragment of .pro:
include(adscreen/adscreen.pri)
(The subproject directory in the adscreen subdirectory of the main project directory.)
Content of adscreen. pri:
TEMPLATE = app
QT += qml quick
CONFIG += c++11
SOURCES += $$PWD/main.cpp
RESOURCES += $$PWD/qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
That is, only added $$PWD
before the file names, the only difference from the previous adscreen. pri
But after all, the main function should be both there and there (I want to run the screen with advertising films on a system without a window manager, that is, like a screensaver), can only library subprojects be connected?
1 answers
One project - one executable file. If you want to have several projects with multiple executable files, you need to combine them into a special project.
To do this, create another pro file, which is located on the level above. And fill it with such content somewhere
# эта строка нужна, если не хочется заморачиваться
# и пусть все проекты собираются в порядке упоминания
CONFIG += ordered
# а это то, что это такой себе "суперпроект"
TEMPLATE = subdirs
# список папок с вложенными проектами
SUBDIRS = server client/simple client/second
That is, now there should be such a structure
project.pro
server/
server.pro
...файлы проекта
client/
simple/
simple.pro
...
second/
second.pro
...
The key point is that the name of the folder and the project that it contains must match. If this is not possible (for a number of reasons), then you can use all the handles prescribe it. That is, you just create a project name (virtual) and specify parameters for it: where the sources are located, on whom it depends. Details in the official documentation. An example of straight ottudov
template = subdirs
SUBDIRS = \
lib2 \ # наши проекты
lib \ эти имена - фейковые
app
# а теперь расскажем qmake где искать данные по проекту
lib2.subdir = src/lib2
lib.subdir = src/lib
app.subdir = src/app
# А также, укажем зависимости
# теперь проекты lib lib2 будут собраться "в паралель" (а могут и по очереди, как получиться) и только потом будет собираться app.
app.depends = lib lib2
This method does not contain the word "ordered" and is the preferred one. It also has a positive effect on the build time.