Qt World Summit: Submit your Presentation

Relationship between project files and build targets

  • Hi -

    Is it possible to build multiple targets from a single project, or is a project by definition designed to build just one target? I'm working on a project (not in the Qt sense of the word) in which I will need to build several binaries. Should I have a separate .pro file for each?


  • No, qmake should be able to build for several targets, based on a single pro-file. You can always use conditions to mark part of a file to be relevant for one of the platforms only.

    Not keeping several files in sync does save a lot of time;-)

  • OK, so if a project contains more than one file with a main() function, then how do the debug/run commands in Creator know which executable to launch?

  • I'm obviously doing this wrong. I tried to add a single-file program to my existing project through the Add Existing Files... menu option. This results in the new file getting folded into the original dependency list in the .pro file, plus I get a build error of a duplicate symbol.

    Can someone educate me on the correct way to add a second main file to an existing project? Thank you.

  • You can put code with the same method names, etc. into one file, but you need to make sure by using the preprocessor macros (#ifdef Q_OS_WIN, etc.) that only one of those is visible at the same time.

    You can also move that platform specific code into separate files, using the build system to only compile those that apply for the target environment you are building for.

    You can not just lump all the code together and hope for the compiler (or whoever) to figure out what you mean.

    You will need one application target in the .pro-files per main() function: So each will be its own binary. You select which "main()" to debug or run by running the binary it belongs to.

    The original question was about having separate .pro-files for all the targets. I would not do that. Does this clarify my earlier answer?

  • Odd...I thought I'd replied to this already.

    Tobias: I'm not trying to use this for platform-specific code. I have a collection of related programs that I thought would be convenient to control under one .pro file, but it appears that's not such a good idea. But yes, you've answered my original question. I'll just plan on a 1:1 ratio between executables and .pro files. Thanks.

Log in to reply