如何修改Qt Creator的项目文件(.pro)中的PATH变量 [英] How to modify the PATH variable in Qt Creator's project file (.pro)
问题描述
LNK1158:无法运行'rc.exe'
我设法通过添加
C:/ Program Files(x86)/ Microsoft SDKs / Windows / v7.1A / Bin
到
项目 - >中的PATH变量构建环境
但是,我需要通过编辑.pro文件修改PATH变量。这将使得更容易在另一台计算机上打开和构建我的项目,因为所有路径都将存储在.pro文件中。此解决方案无效:
PATH + =C:/ Program Files(x86)/ Microsoft SDKs / Windows / v7。 1A / Bin
是否可能?
奇怪的是,您有这样的错误,因为Qt Creator应该检测MSVC编译器并在适当的环境中构建项目。 Qt Creator知道它应该运行所需的批处理文件来准备VS Command Prompt控制台的环境,例如 C:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat x86
无论如何,可以写 qmake
项目文件(
.pro
)创建在实际项目编译之前运行任何自定义shell命令的Makefile。
当 qmake
进程 .pro
文件时,它只会创建Makefile。然后编译由其他make构建工具完成。 Qt Creator使用它的 jom
make实用程序。从VS控制台可以运行 nmake
。
使实用程序按照Makefile规则中的指定运行不同的工具。可以使用设置 PATH
变量的构建命令创建额外的虚假目标。主要目标应该取决于此目标。
.pro
文件中的以下行创建此类规则: p>
QMAKE_EXTRA_TARGETS + = customtarget1
customtarget1.target = dummy
customtarget1.commands = set PATH = C:/ Program Files(x86)/ Microsoft SDKs / Windows / v7.1A / Bin; $(PATH)
PRE_TARGETDEPS + = dummy
因此,在处理Makefile时,第一个目标是 dummy
。它的构建命令设置 PATH
。然后所有其他工具都在该环境中运行。
I use Qt Creator 3.4.2 for Windows and MSVC2013 compiler. When I build the project I get an error:
LNK1158: cannot run 'rc.exe'
I managed to fix it by adding
"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Bin"
to the PATH variable under
Projects -> Build Environment
But I need to modify the PATH variable by editing the .pro file. This would make it easier to open and build my project on another computer because all the paths would be stored in the .pro file. This solution does not work:
PATH += "C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Bin"
Is it possible at all?
It is strange that you have such error, since Qt Creator should detect MSVC compilers and build project in appropriate environment. Qt Creator knows that it should run required batch file to prepare environment of VS Command Prompt console, for example C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat x86
Anyway, it is possible to write qmake
project file (.pro
) that creates Makefiles that run any custom shell command before actual project compilation.
When qmake
processes .pro
file it only creates Makefiles. Then the compilation is done by other make build tool. Qt Creator uses its jom
make utility. From VS console it is possible to run nmake
.
Make utility runs different tools according to specified in Makefiles rules. It is possible to create additional phony target with build command that sets PATH
variable. The main target should depend on this target.
The following lines in .pro
file create such rules:
QMAKE_EXTRA_TARGETS += customtarget1
customtarget1.target = dummy
customtarget1.commands = set PATH=C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Bin;$(PATH)
PRE_TARGETDEPS += dummy
So, during processing Makefiles the first target is dummy
. Its "build" command sets PATH
. Then all other tools run in that environment.
这篇关于如何修改Qt Creator的项目文件(.pro)中的PATH变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!