Results 1 to 4 of 4

Thread: Dependencies maintenance headache

  1. #1
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Dependencies maintenance headache

    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.
    Last edited by nateriver; 22nd December 2009 at 15:45.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dependencies maintenance headache

    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:
    Qt Code:
    1. CONFIG(debug, debug|release) {
    2. D=_d
    3. export(D)
    4. }
    5.  
    6. LIBS += -L/path/to/libs -lmylib$${D}
    To copy to clipboard, switch view to plain text mode 

    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 page on the wiki.
    Last edited by franz; 22nd December 2009 at 21:20. Reason: updated contents
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. The following user says thank you to franz for this useful post:

    nateriver (23rd December 2009)

  4. #3
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dependencies maintenance headache

    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?

  5. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dependencies maintenance headache

    Have a look at this. The QMAKE_COPY variable contains the copy function for your platform with possibly some extra parameters.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  6. The following user says thank you to franz for this useful post:

    nateriver (28th December 2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.