如何在QT中从.pro编译完成后执行shell命令?
如果我想执行 chmod 命令、执行输出二进制文件或执行其他一些操作,我必须对 .pro 文件进行哪些更改。
What changes must I make to the .pro
file if I want to execute chmod
command, execute the output binary file, or do some other operations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有类似的问题。我想要一个特殊的工具(版本管理器)在每次执行 Makefile 时运行代码。这是解决方案:(
在 中阅读Qmake 手册,配置 qmake 环境,部分:自定义 Makefile 输出)
创建您自己的 Makefile 目标。指定命令等。
这样,您就有了一个可以使用
make mytarget
调用的额外目标。如果您想将其与实际的构建目标联系在一起,您必须添加:希望有帮助。
最好的问候
D
I had a similar problem. I wanted a special tool (versioner) to run over the code every time the Makefile was executed. Here's the solution:
(to be read in the Qmake Manual, Configuring qmake's Environment, Section: Customizing Makefile Output)
Create you own Makefile target. Specify the command etc.
This way, you have an extra target you can call with
make mytarget
for example. If you want to tie it together to the actual buildtarget you'll have to add:Hope that helps.
Best regards
D
按给定顺序制作内容的另一种方法是使用空的“超级”目标:
其中
first
- 是默认的 qmake 目标,target_pre
和target_post
一些自定义目标。现在make super
就做这件事吧。编辑:看起来在 Qt 的最新版本中,依赖项构建是并行运行的,因此该解决方案不起作用。
Another way to make things in given order is to use empty "super" target:
Where
first
- is default qmake target, andtarget_pre
andtarget_post
some custom targets. Nowmake super
just do the thing.EDIT: looks like in last versions of Qt build of dependencies is running in paralell so this solution wouldn't work.
如果您使用的是 Qt Creator,则可以在“项目”面板中添加自定义构建步骤: http://doc.qt.nokia.com/qtcreator-2.1/creator-build-settings.html#adding-custom-build-steps
If you are using Qt Creator, you can add custom build steps in the Projects panel: http://doc.qt.nokia.com/qtcreator-2.1/creator-build-settings.html#adding-custom-build-steps
正确的答案取决于您想要什么以及何时想要。但是,正如之前发布的一些评论所示,
QMAKE_POST_LINK
可能是您想要的,而不是POST_TARGETDEPS
。查看此相关帖子:
QMake:构建后执行脚本
其一,当您使用
POST_TARGETDEPS 在创建 exe 之前(在 Windows 中)或在重新创建 exe 之前(在 Linux 中)触发! QMake 的工作方式因平台和编译器而异。
重新编译 exe 时,我需要对其进行一些“符号处理”。
POST_TARGETDEPS
在 Windows(使用 mingw)和 Linux(使用 gcc)中都给我带来了问题。在Windows中,它过早地执行了我的脚本,而在Linux中,它在我修改了它之后覆盖了我的exe(即,在我在外部脚本中剥离它之后,将我的调试信息添加回exe)。然而,QMAKE_POST_LINK
在这两种情况下都运行得很好。相比之下,它也更短、更甜、更清晰!The right answer depends on exactly what you want, and when. However, as seen in some previously posted comments here
QMAKE_POST_LINK
is probably what you want rather thanPOST_TARGETDEPS
.Check out this related post:
QMake: execute script after build
For one, when you use
POST_TARGETDEPS
that fires off BEFORE your exe is created (in Windows) or BEFORE it is recreated (in Linux)! QMake works differently depending upon the platform and the complier.I needed to do some "symbols processing" on an exe when it was recompiled.
POST_TARGETDEPS
gave me problems in both Windows (using mingw) and Linux (using gcc). In Windows, it executed my script prematurely, and in Linux it overwrote my exe after I had modified it (i.e. added back my debugging info to the exe after I had stripped it in my external script).QMAKE_POST_LINK
worked perfectly, however, in both cases. It's also short, sweet, and more clear by comparison!