PDA

View Full Version : Dependencies maintenance headache



nateriver
22nd December 2009, 15:41
Greetings.
I'm using QtCreator 1.3.0, Qt 4.6 (2009.05). There are two projects: project A - dynamic library with just one Qt subclass, project B - executable using project A as dependency.
I've specified project A as a dependency for project B in "Projects" tab in QtCreator.
Now when I press build project, everything seems fine, project A compiles first, then project B is compiled and... throws an error where I'm including headers from project A. Simple problem at a glance, so I've just added "INCLUDEPATH += path\to\A" to project B's *.pro file. Now both project are compiled fine, but linking fails due to unresolved symbols, which means that compiler does not know where to look for *.a files (since I'm using mingw) And that's where headache starts. After some searching, I found that I should add "LIBS += path\to\lib.a" directive to project file. That is what I have done. And voila! Everything is working as it seems it should... BUT if I try to compile project B in release mode, it actually links in debug version of project A, since path to the lib file is hardcoded! That's definitely not what I would want. So now every time I switch configuration I have to manually edit project file.

The question is - is there any way to automate this task, or maybe even more elegant solution for managing dependencies than editing project file by hand?

P.S. I also noticed that there are two Makefiles generated by qmake - Makefile.Release and Makefile.Debug. They both contain almost the same parameters, except for some optimization and linker flags. Is it the way it should be that qmake generates separate makefiles based on ONE project file? But what if I want (as I described before) to use different parameters (maybe even different source files) for different configurations of ONE project (so don't propose using separate project files)? That seems confusing to me. Well, at least confusing concerning QtCreator; maybe qmake itself allows such things.

franz
22nd December 2009, 21:17
You could add a postfix to your libraries: projecta_d and projectb_d for debug and just projecta and projectb for release. You can achieve such behavior as follows:


CONFIG(debug, debug|release) {
D=_d
export(D)
}

LIBS += -L/path/to/libs -lmylib$${D}


This will automate the exact behaviour shown above.

It may be a bit of a qmake hack. The Qt guys have done something like this in the qmake projects for the Qt libraries as well. You might want to have a look at those, as well as the undocumented qmake (http://wiki.qtcentre.org/index.php?title=Undocumented_qmake) page on the wiki.

nateriver
23rd December 2009, 05:12
Thanks for the reply and for the link especially; I've solved the problem using separate configurations in project file and specifying "-config" flag for different build configurations in QtCreator. (Projects->Build Settings->Build Steps->QMake->Show Details->Additional Arguments).

The only issue left is running application from QtCreator. Since my application uses shared library (dynamic), this library should be in the same dir as exe or in PATH. I've set up two run configurations (for debug and release) in QtCreator and added output directories of that library project to PATH. That works as expected, but I have a feeling that it's not the best ever solution, since I have to switch configurations manually, so I may forget about it and compile any changes to the code in debug mode but launch release (x_x)

Maybe it's possible to copy resulting shared library (from project A) to project B's output directory using qmake?

franz
27th December 2009, 12:26
Have a look at this (http://doc.trolltech.com/4.6/qmake-environment-reference.html#customizing-makefile-output). The QMAKE_COPY variable contains the copy function for your platform with possibly some extra parameters.