[英]Specifying dependencies between SUBDIRS projects with .depends doesn't work
I'm having problems setting up dependencies between subprojects in the context of a qmake SUBDIRS
project. 我在qmake SUBDIRS
项目的上下文中设置子项目之间的依赖关系时遇到问题。
I'm using the .depends
option to establish the dependency of one project on another, expecting the former to be recompiled when the latter is modified, but this doesn't happen - the latter is recompiled after the modification, but the dependent project is not. 我正在使用.depends
选项来建立一个项目对另一个项目的依赖关系,希望前者在修改后者时会重新编译,但这不会发生-后者在修改后会重新编译,但是依赖项目是不。
Am I misunderstanding the meaning of the .depends
option? 我是否误解了.depends
选项的含义?
Here's a minimal example that illustrates the problem: 这是一个说明问题的最小示例:
+mysubdirs/
| mysubdirs.pro
| +mylib/
| | mylib.pro
| | MyClass.h
| | MyClass.cpp
| +myapp/
| | myapp.pro
| | main.cpp
mysubdirs.pro : mysubdirs.pro :
TEMPLATE = subdirs
SUBDIRS += mylib
SUBDIRS += myapp
CONFIG += ordered
myapp.depends = mylib
mylib.pro : mylib.pro :
TEMPLATE = lib
CONFIG += staticlib
HEADERS = MyClass.h
SOURCES = MyClass.cpp
myapp.pro : myapp.pro :
TEMPLATE = app
SOURCES = main.cpp
LIBS += "../../build-mysubdirs/mylib/libmylib.a"
INCLUDEPATH += ../mylib
MyClass.h : MyClass.h :
#ifndef MYCLASS_H
#define MYCLASS_H
class MyClass
{
public:
MyClass();
};
#endif // MYCLASS_H
MyClass.cpp : MyClass.cpp :
#include "MyClass.h"
#include <iostream>
MyClass::MyClass()
{
std::cout << "in constructor" << std::endl;
}
main.cpp : main.cpp :
#include "MyClass.h"
int main()
{
MyClass x;
return 0;
}
Compile the subdirs project. 编译subdirs项目。 Then change the string "in constructor" to something else and recompile: the output of myapp is unchanged. 然后将字符串“ in constructor”更改为其他内容并重新编译:myapp的输出未更改。
Am I misunderstanding the meaning of the .depends option? 我是否误解了.depends选项的含义?
Yes, you are. 是的,你是。
Basically, qmake
is a "Makefile"-generator. 基本上, qmake
是一个“ Makefile”生成器。 And ".depends" here means "a dependency in a generated Makefile". “ .depends”在这里表示“生成的Makefile中的依赖项”。 So myapp.depends = mylib
becomes myapp: mylib
in a root Makefile. 因此, myapp.depends = mylib
成为myapp: mylib
根Makefile中的myapp: mylib
。
However, both mylib
and myapp
(being SUBDIRS
) are just .PHONY
targets which perform recursive make invocations. 但是, mylib
和myapp
(作为SUBDIRS
)都只是.PHONY
目标,它们执行递归的make调用。 So, at the end of the day, make will run two sub-makes, which absolutely do not depend on each other (as it's usual with a recursive make pattern), except one sub-make always runs before the other (because of a target-prerequisite relation in a root Makefile). 因此,在一天结束时,make将运行两个子make,这两个子make绝对不相互依赖(这与递归make模式是很常见的),只是一个子make总是在另一个子make之前运行(因为根Makefile中的target-prerequisite关系)。
By the way, it means that CONFIG += ordered
makes no sense here and should be omitted (in fact, it's deprecated in favour of .depends
). 顺便说一句,这意味着CONFIG += ordered
在这里没有意义,应该省略(实际上,它已被.depends
)。
Now, considering recompilation of myapp
: it turns out that your executable DOES NOT depend on your library (in a "make-sense"), except that library is mentioned in $$LIBS
(ie linker flags). 现在,考虑重新编译myapp
:事实证明,可执行文件不依赖于您的库(在“ make-sense”中),除了在$$LIBS
提到了库(即链接器标志)。 To fix this issue you have to add your library to the application target dependency list manually: 要解决此问题,您必须将库手动添加到应用程序目标依赖项列表中:
myapp.pro myapp.pro
PRE_TARGETDEPS += path/to/mylib.a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.