English 中文(简体)
How to get qmake to generate "project dependencies" in a Visual Studio .sln project
原标题:
  • 时间:2010-02-24 15:21:15
  •  标签:
  • c++
  • qt
  • qmake

I have a qmake build of a few libraries and an app which depends on them. Using the subdirs template I m able to get qmake to output a .sln file which works almost to my liking in VC2008. Though I ve specified the dependencies between the targets in every way I ve seen described, I end up with no "project dependencies" in the .sln file, and I have to add these in manually.

So far I ve tried

CONFIG += ordered

with correct ordering to no avail.

And similarly the more arcane syntax:

client.depends = core common

Which also doesn t work. No dependencies whatsoever show up when I load the sln.

问题回答

Both CONFIG += ordered and target.depends = are not supported by the qmake s MSVC backend (solution generator). Back in 2010 with Qt 4.7 around, the docs didn t mention that, but in Qt 4.8 the developers have updated the docs accordingly (see the Target section remarks):

  • .depends This subproject depends on specified subproject. Available only on platforms that use makefiles.
  • The ordered option is not supported for Visual Studio.

But they had provided a workaround (which is discussed in that cryptic post), and it s still valid and even documented in the same target section. Too bad I had to rebuild qmake and use a debugger to verify that:

  1. a) There is a Lib/DLL project of which TARGET (the .lib is used and not the .dll) is used on the link line of another project in your solution (you can modify the link line with LIBS).

    b) There is an Exe project of which TARGET is used in a custom build-step of another project in your solution.

  2. You don t use paths in the TARGET variable (use DESTDIR/DLLDESTDIR for that), e.g, TARGET=$(SOME_VARIABLE)/myLib, won t work.
  3. If you have a special location for your libs, you specify the -Lmy/library/path and LIBS += mylib, instead of just using LIBS += my/library/path/mylib
  4. The leaf projects are created before you generate the solution file. (You can use the recursive flag for qmake to do this, like "qmake -tp vc -r [yourproject.pro]"

Basically, qmake will generate dependency when your lib s target name (yourlib.lib) is equal to the one of the import libraries of the final app (that has LIBS += yourlib.lib). (See qmake s source where the import libraries are added as dependencies, and a little further where they re compared with the project target names)

Here is the minimal setup that generates dependencies in the solution:

solution.pro
  TEMPLATE = vcsubdirs
  SUBDIRS = main app

app/app.pro
  LIBS += main.lib

main/main.pro
  TARGET = main
  TEMPLATE = vclib

With those, if you run qmake -r -tp vc, you ll get the explicit dependency in the generated .sln:

GlobalSection(ProjectDependencies) = postSolution
    {E634D0EB-B004-3246-AADA-E383A376158F}.0 = {1BD6E999-63E6-36F5-99EE-1A650332198C}
EndGlobalSection

From an old mailing list entry: http://lists.trolltech.com/qt-interest/2006-07/thread00238-0.html

It appears that it tries to figure out which things are dependent for you. Are you able to build from the sln without entering the project dependencies manually?

I am not a wiz in makefiles but if I were you, I would try to recreate that dependency in with QtCreator by editing the .pro file, running qmake then looking at the auto-generated result in the MAKLEFILE. If you want to know how qmake works then look at the qt documentation.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签