首页 > 解决方案 > QMake/QtCreatir 将二进制文件复制到给定位置的好策略是什么

问题描述

我正在使用 QtCreator 为 Android 编译一个库。构建完成后,我需要将其复制到特定位置。

我将 QtCreator 4.0.3 与 Qt 5.6 和 NDK r11b 一起使用

我现在正在使用 Qt 5.12 和 NDK r18b 将我的代码迁移到 QtCreator 4.8.0

使用 QtCreator 4.0.3,我曾经拥有:

DESTDIR = <path to the place where I wish the binary to be copied>

它工作得很好(.so文件在生成后被复制)

使用 QtCreator 4.8.0 我得到错误:

move libsde3p_cppunit-g.so <path to the place where I wish the binary to be copied>\libsde3p_cppunit-g.so
process_begin: CreateProcess(NULL, move libsde3p_cppunit-g.so <path to the place where I wish the binary to be copied>\libsde3p_cppunit-g.so, ...) failed.
make (e=2): Le fichier spécifié est introuvable.

我看到当这个错误被报告<my build folder>\build-cppunit-Android_for_armeabi_v7a_Clang_Qt_5_12_0_for_Android_ARMv7-Debug\libsde3p_cppunit-g.so时存在,而<my build folder>\build-cppunit-Android_for_armeabi_v7a_Clang_Qt_5_12_0_for_Android_ARMv7-Debug\android-build\libs\armeabi-v7a\libsde3p_cppunit-g.so还没有。而且我知道 QtCreator 最终将 lib 从第一个位置复制到第二个位置。所以很可能,它会尝试从错误的位置复制库。

我尝试了其他一些选择:

试过QMAKE_POST_LINK = copy...这显然永远不会执行(QMAKE_POST_LINK = djdkdk不报告任何错误)。

尝试自定义目标:

custom_copy_step.target = foo.h
custom_copy_step.commands = $(COPY_FILE) $$shell_path($$OUT_PWD)\lib$${TARGET}.so $$shell_path(<path to the place where I wish the binary to be copied>
QMAKE_EXTRA_TARGETS += custom_copy_step
POST_TARGETDEPS += foo.h

这次它失败并出现错误:

copy /y <my build folder>\build-cppunit-Android_for_armeabi_v7a_Clang_Qt_5_12_0_for_Android_ARMv7-Debug\libsde3p_cppunit-g.so <path to the place where I wish the binary to be copied>
Le fichier sp‚cifi‚ est introuvable.
make: *** [foo.h] Error 1

而且我确认 lib 文件不存在于磁盘上,因此看起来该命令是在实际生成 .so 之前执行的。

我应该在我的 .pro 文件中添加哪些指令以将输出 .so 文件复制到特定位置?

标签: androidqt-creatorqmake

解决方案


可以使它与QMAKE_POST_LINK(需要 a+=而不是=)一起工作:

QMAKE_POST_LINK += $(COPY_FILE) $$shell_path($$OUT_PWD)\lib$${TARGET}.so $$shell_path(<path to the place where I wish the binary to be copied>)

推荐阅读