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.