admin管理员组文章数量:1200965
In qmake, I want to copy a file from my source directory to the build directory. I noticed that Windows uses \
in paths, so I made sure to replace it accordingly, as shown in the code below:
win32:CONFIG(debug, debug | release)
{
# target file
TargetConfig = $${PWD}/config.ini
TargetConfig = $$replace(TargetConfig, /, \\)
# output directory
OutputDir = $${OUT_PWD}/$${DESTDIR}
OutputDir = $$replace(OutputDir, /, \\)
# copy
# QMAKE_POST_LINK += $$QMAKE_COPY_DIR \"$$TargetConfig\" \"$$OutputDir\" > log.txt
QMAKE_POST_LINK += cmd /C copy \"$$TargetConfig\" \"$$OutputDir\" > log.txt
}
However, I found that after the build, the file was not copied. When I checked the log.txt
file, it seemed to only contain some information about the cmd
startup, meaning that the copy
command was not executed. I then tried executing the copy
command in the cmd
terminal, and it successfully copied the file, so I was puzzled as to why it didn't work in the build.
After researching, I found that I could use QMAKE_COPY_DIR
, which generates the appropriate copy command
for different platforms. After using this command, the file was successfully copied during the build, and I found that the build log used the cp
command for the copy operation, as shown in the image below:
I noticed this issue In mingw,qmake copy_dir is always error, but the answer to this question did not resolve my doubts.
I am using QT 6.8.1
, with mingw32-make
as the build tool, and the operating system is Windows
. Therefore, my questions are:
- Why can't the
copy
command copy the file during the build process? - Why is the
cp
command fromUnix
used instead of thecopy
command fromWindows
?
In qmake, I want to copy a file from my source directory to the build directory. I noticed that Windows uses \
in paths, so I made sure to replace it accordingly, as shown in the code below:
win32:CONFIG(debug, debug | release)
{
# target file
TargetConfig = $${PWD}/config.ini
TargetConfig = $$replace(TargetConfig, /, \\)
# output directory
OutputDir = $${OUT_PWD}/$${DESTDIR}
OutputDir = $$replace(OutputDir, /, \\)
# copy
# QMAKE_POST_LINK += $$QMAKE_COPY_DIR \"$$TargetConfig\" \"$$OutputDir\" > log.txt
QMAKE_POST_LINK += cmd /C copy \"$$TargetConfig\" \"$$OutputDir\" > log.txt
}
However, I found that after the build, the file was not copied. When I checked the log.txt
file, it seemed to only contain some information about the cmd
startup, meaning that the copy
command was not executed. I then tried executing the copy
command in the cmd
terminal, and it successfully copied the file, so I was puzzled as to why it didn't work in the build.
After researching, I found that I could use QMAKE_COPY_DIR
, which generates the appropriate copy command
for different platforms. After using this command, the file was successfully copied during the build, and I found that the build log used the cp
command for the copy operation, as shown in the image below:
I noticed this issue In mingw,qmake copy_dir is always error, but the answer to this question did not resolve my doubts.
I am using QT 6.8.1
, with mingw32-make
as the build tool, and the operating system is Windows
. Therefore, my questions are:
- Why can't the
copy
command copy the file during the build process? - Why is the
cp
command fromUnix
used instead of thecopy
command fromWindows
?
2 Answers
Reset to default 0On Windows qmake
genereates makefiles with cp
instead of copy
if cp
is available, meaning if cp
is found in %path%
environment variable, that makes sense when you compile on msys2
shell or cygwin
shell for example, and leads to very confusing errors sometimes when it's not intentional.
You probably added something like C:\msys64\usr\bin
or C:\Program Files\Git\usr\bin
into path
by mistake or intentionally.
You can open shell and run where cp
to find out offending path.
I checked it on my machine, it works. But theres some caviats: make does not rebuild target unless one of sources has changed (no linking means no postlink mingw32-make[1]: Nothing to be done for 'first'.
), so command is not executed in this case.
Run rebuild, remove target binary or touch any source file to trigger target build.
You can locate actual command in Makefile.Debug
by searching config.ini
and make sure its correct.
本文标签: qtWhy can39t the copy command copy the file during the build processStack Overflow
版权声明:本文标题:qt - Why can't the copy command copy the file during the build process? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738623432a2103325.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论