如何在Qt中为qmake指定库文件依赖?
有一个 SomeLib.pro 文件,其中包含:
CONFIG += debug
TEMPLATE = lib
TARGET = SomeLib
..
然后在依赖的 SomeApp.pro 中:
..
debug:LIBS += -lSomeLib_debug
..
如果我在 qmake 中触及 SomeLib,如何强制构建 SomeApp?
Have a SomeLib.pro file that contains:
CONFIG += debug
TEMPLATE = lib
TARGET = SomeLib
..
Then in a dependent SomeApp.pro:
..
debug:LIBS += -lSomeLib_debug
..
How can I force SomeApp to build if I touched SomeLib in qmake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
它很丑陋,因为您需要给出确切的库文件名,但这应该可以工作:
TARGETDEPS += libfoo.a
It's ugly because you need to give the exact library file name, but this should work:
TARGETDEPS += libfoo.a
如果您在应包含该库的项目的上下文菜单中单击“添加库...”,QT Creator 将完成这项工作。
这些变量会自动为您配置:
另请参阅 http://doc.qt.digia.com/qtcreator-2.1/creator-project-qmake-libraries.html
QT Creator will do the work if you click "Add library..." in the context menu of the project that should include the library.
These variables are configured automatically for you:
See also http://doc.qt.digia.com/qtcreator-2.1/creator-project-qmake-libraries.html
在回复 Zahir 的评论时,也许值得指出的是,如果使用 DLL,则在 qmake 文件中声明这种依赖关系是不必要的,但如果您的 exe 依赖于静态库,则必不可少。
In reply to Zahir's comment, it's perhaps worth pointing out that stating this dependency in qmake files is unnecessary if using DLLs, but is essential if your exe depends on a static library.
qmake
不提供这种能力。相反,请将您的应用程序和 lib 放在子目录中,然后在其父目录中创建一个 Makefile,如下所示:
然后始终从此目录运行
make
。qmake
does not provide this ability.Instead, put your app and lib in subdirectories, then create a Makefile in their parent directory that looks something like this:
Then always run
make
from this directory.我使用:
它可以工作,但很笨拙,因为必须指定库的完整路径,这对于每个操作系统/编译器来说都是不同的。
I used:
It works, but is clumsy since it is necessary specify full path to library, which is different for every operating system/compiler.
当然这是不可能的,您正在谈论使用 qmake 进行反向依赖项查找? 那么您想要的是在对库 A 进行更改后构建应用程序 B(以及依赖于库 A 的任何其他应用程序)?
这有点像说如果 vbrun300.dll 更新则重新编译所有 Visual Basic 应用程序?
surely that can't be possible, you are talking about using qmake to do a reverse dependency lookup? so what u want is for it to build app B (and any other app dependent on library A) after you've made a change to library A?
that's a bit like saying recompile all visual basic apps if vbrun300.dll is updated?