john-charles
john-charles

Reputation: 1469

Qt Creator, how do I add one c++ project to another?

This seems like something that should be really simple, yet there doesn't seem to be a way to do it as one would expect.

I have two separate c++ projects open in qt creator, and I would like to include/compile against one project in the other.

Here's my layout:

project_a/
    project_a.pro
    someheaders.h
    somecode.cpp
    main.cpp

project_b/
     project_b.pro
     someheaders.h
     somecode.cpp
     main.cpp

Basically I want to be able to include the files from project_a in project b. I have set project_a to be a dependency within project_b but that seems to have been wholly ineffectual as a means of using the two projects. What do I do?

Upvotes: 7

Views: 8499

Answers (1)

Sergey Shambir
Sergey Shambir

Reputation: 1592

In order to open & build both project as one, use meta-project with type subdirs:

TEMPLATE = subdirs
SUBDIRS += project_a project_b
# Use ordered build, from first subdir (project_a) to the last (project_b):
CONFIG += ordered

You should put subproject any_name.pro to directory any_name, and place this directory next to meta-project .pro file.

If you want include headers from other project, write project_a.pri file that contains, for example:

# PWD expands to directory where project_a.pri placed.
INCLUDEPATH += $$PWD/
INCLUDEPATH += $$PWD/network

Than include this file to project_b.pro:

include(../project_a/project_a.pri)

If you want use project_a as library, change it to TEMPLATE = lib and add library with wizard, available in context menu when project_b.pro opened in editor.

Upvotes: 5

Related Questions