QT Creator "subdirs" project
-
Hi all,
I've just started following along with Stanford's CS106X course through their online course material, to brush up on my (quite mediocre) C++. The course uses QT Creator, so I've installed version 4.0.2 on my OS X system.
The course material includes a QT "starter project"
(http://web.stanford.edu/class/archive/cs/cs106b/cs106b.1162/qtcreator/simple-project.zip)
that includes the "Stanford CPP" libraries. Note that this is not a pre-compiled library, rather, the source (.h and .cpp) files are present. I would like to use these libraries for various mini-projects I might be making as I follow along the course.What I would like to know about is the most "hassle-free" way I could keep my projects together and automatically import the requisite libraries.
I noticed QT Creator allows making something called "subdir" projects. In the aforementioned starter project, the .pro file has the line
TEMPLATE = app
I tried changing this to
TEMPLATE=subdirs
and after Qt Creator re-parses the file, it allows me to right-click on the project name and chose the (previously greyed out) "New subproject" option.
Now after I create a new subproject, is there something I can do to make the include files (and corresponding sources) available to it? I understand I should be able to put things into the .pro file to tell the build system where everything is (although I haven't tried it yet), but is there a more straightforward way, by virtue of the "subproject" relationship?
-
Does this help? https://wiki.qt.io/SUBDIRS_-_handling_dependencies
-
Not sure; I think the document you linked is for when you want to share a pre-built library.
I'm guessing my question isn't very well specified - all I wanted was a good way to create projects that allow me to
#include "someheader.h"
from the parent project (i.e. the Stanford CPP code) that the linker can resolve, without having to worry about relative paths or having to passing additional include/source directories to the build/linker system for every new project - or (alternatively) having to add a duplicate copy of the Stanford code I want to reuse in every project.This might seem like a frivolous requirement, but I guess I was just hoping to minimize the "cognitive load" (i.e. learning c++ - the language - without the added burden of having to understanding the IDE or build system right away. But maybe that's just me being lazy.)
I suppose if I built the Stanford CPP sources as a static library first then I could use the ideas in the page you linked.
In any case, thanks!
-
Not sure; I think the document you linked is for when you want to share a pre-built library.
I'm guessing my question isn't very well specified - all I wanted was a good way to create projects that allow me to
#include "someheader.h"
from the parent project (i.e. the Stanford CPP code) that the linker can resolve, without having to worry about relative paths or having to passing additional include/source directories to the build/linker system for every new project - or (alternatively) having to add a duplicate copy of the Stanford code I want to reuse in every project.This might seem like a frivolous requirement, but I guess I was just hoping to minimize the "cognitive load" (i.e. learning c++ - the language - without the added burden of having to understanding the IDE or build system right away. But maybe that's just me being lazy.)
I suppose if I built the Stanford CPP sources as a static library first then I could use the ideas in the page you linked.
In any case, thanks!
You can alternatively setup a pri file with all the Stanford code. And include that pri file in each of your separate projects. This way you would not need a subdirs project.
-
You can alternatively setup a pri file with all the Stanford code. And include that pri file in each of your separate projects. This way you would not need a subdirs project.
-
Hi,
Do you mean move all your files to the subproject folder used to build your library ?
-
@SGaist said in QT Creator "subdirs" project:
Hi,
Do you mean move all your files to the subproject folder used to build your library ?Let me explain:
This is the file structure I get when I unzip the starter project (i've left out some things I feel are non-essential):
simple_project - simple_project.pro - lib - StanfordCPPLib - *.h - *.cpp - private - *.h - stacktrace - *.h - *.cpp - src - *.h - *.c
As per how the .pro file is configured, the student is expected to complete an assignment by writing all his code in the
src
folder, and he can just#include
headers fromStanfordCPPLib
and hit "Build". However, this way allows only having one file containingmain()
in thesrc
folder. What I would rather be able to do is make multiple projects relying on the same code (StanfordCPPLib
), but which are otherwise independent of one another, each having its ownmain()
function, and do it in a way that would allow me to keep all these "sister projects" together in the same hierarchy in a non-interfering way whilst making the least amount of additions to the .pro files or build system boilerplate.Even though this is just for learning purposes and I can conceive of several (inelegant) ways of getting around the issue, I was wondering what the best way would be in this situation.
(I still have to look into @t3685's suggestion, at first glance it seems closest to what I want.)
-
A more flexible sub-project setup:
complex_project - sub_project.pro - lib - lib.pro <- TEMPLATE = subdirs - StanfordCPPLib - StanfordCPPLib.pro - StanfordCPPLib.pri <- will be included by your applications - *.h - *.cpp - private - *.h - stacktrace - *.h - *.cpp - apps - apps.pro <- TEMPLATE = subdirs - my_app - my_app.pro -> include(../../lib/StanfordCPPLib/StanfordCPPLib.pri) - *.h - *.cpp
StanfordCPPLib.pri
will contain statements likeÌNCLUDEPATH
andLIBS
to set things up for the projects using that library. Doing so will avoid duplication in your apps .pro file. -
Hi,
Not my knowledge.
-
In your main pro file :
TEMPLATE = subdirs SUBDIRS += \ ADD YOUR SUBDIR NAME HERE
#To use ordered build: CONFIG += ordered
In your subdir pro file:
TARGET= ... QT += ... SOURCES += \ ... HEADERS += \ ... FORMS += \ ... RESOURCES += \ ...
@Raad Please avoid
ordered
and specify the dependencies directly.See this very good blog post.
-
@Raad Please avoid
ordered
and specify the dependencies directly.See this very good blog post.