3
votes

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?

1
Perhaps you're aware of it already, but this is not a good idea if you work with other people on the project, due to their SDKs potentially being in a different location.Mitch
Of course hard-coding SDK paths in the .pro file is not the best solution. But in my case if the SDK versions are the same, the paths will be the same on different machines. Also it would be much easier to modify them (just copy-and-paste) in the .pro file than changing them manually one by one for every build configuration in Projects -> Build Environment.lvds

1 Answers

2
votes

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.