ImaginativeThinking.ca


A developers blog

Why the Heck does Qt Creator fail to build using Visual Studio

By: Brad

Hi Brad I’m trying to use Qt Creator as my IDE but have it use MSVC as the compiler however I keep getting this error when I try to build; What is going on?

'cl' is not recognized as an internal or external command,
operable program or batch file.
jom: *******\Makefile.Debug [obj\debug\***********.obj] Error 1

frusturatedPig

I had this exact same error just the other day and it drove me batty for quiet some time.

I was trying to build a project using Visual Studio 2012 because my dependencies were all Visual Studio 2012 binaries however I don’t know about you but I can’t stand the Visual Studio 2012 (or Visual Studio 2015) IDE when it comes to editing QML scripts so I wanted to use Qt Creator as my IDE. That and Visual Studio is missing some basic table stakes when it comes to being a C++ IDE. Visual Studio is absolutely fantastic and I’m a big fan of it when it comes to being a C# IDE but for C++ its missing some pretty basic features in terms of refactoring tools.

But as you ran into Qt Creator fails to build using Visual Studio compiler. I got the same error as you. The odd thing was that I have used Visual Studio 2015’s compiler in Qt Creator at home with no problems it was my work machine which was throwing the cl not found error.

My first thought when I was troubleshooting this was to check my kit for MSVC as this must be configuration related. The kit in Qt Creator tells it which compiler and version of Qt I want to use when I build.

qt_creator_kits

Looks right to me so then I checked to make sure Qt Creator could find the compiler. Humm that looks like its setup correctly too.

qt_creator_msvc_compiler

Bottom line the issue is that Qt Creator is just an editor and it uses other tools to do the actual compiling. Compilers are all command line tools which Qt Creator can just call when you tell it to build your application. The trouble is that these tools might be installed anywhere on your machine so Qt Creator (and the tools themselves) rely on the PATH environment variable to locate the tools.

For MSVC there are a few environment variables which need to be setup and locations which need to go in the PATH before you can call it from the command line. These things the Visual Studio IDE does for you.

Microsoft very nicely however deploy a batch script with the compiler which sets all that up for you called vccarsall.bat. As you can see in the above image Qt Creator knows where that batch file is and is calling it correctly.

Since I’m defently having a path problem I tried to run the batch file my self to see if it was working.

Turns out it was not and I was getting an error stating \Microsoft was not expected at this time.

I did some digging in the batch files and discovered that my problem was being caused by my PATH environment variable.

See batch files have issues with spaces and when you put a path which has spaces in a batch file you need to wrap it in quotation marks so that the batch interpreter knows this is a single string.

That is if we want the following to be read as one string instead of four we need to put it in quotation marks.

“C:\Program Files\Microsoft Visual Studio”

The issue is that not all batch scripts watch out for this and you can get into issues if you don’t feed it pre-wrapped directory paths. Because I’ve been burned by this in the past I got in the habit of either not using spaces in my folder names (best practice really) or when I add them to my path I pre-wrap them. I think maybe on older versions of Windows you did need to pre-wrap your directory locations when adding them to the PATH variable.

Either way turns out my existing PATH environment variable had three paths in it which were already wrapped in quotes and the vcvarsall.bat file (or rather the batch file it was calling vcvars32.bat) was also wrapping the string value it got out of the PATH variable which caused the batch interpreter to screw up on the quotation marks and resulted in my error.

To fix it I removed the quotation marks from my PATH variable and presto the error went away and I was able to successfully use Qt Creator to build using MSVC.

So that might very well be why Qt Creator fails to build using Visual Studio for you. I hope this helps, if you have any questions or comments feel free to leave them below and I’ll try to answer them as time permits.

Until next time think imaginatively and design creatively

Brad

My interest in computer programming started back in high school and Software Development has remained a hobby of mine ever since. I graduated as a Computer Engineering Technologist and have been working as a Software Developer for many years. I believe that software is crafted; understanding that how it is done is as important as getting it done. I enjoy the aesthetics in crafting elegant solutions to complex problems and revel in the knowledge that my code is maintainable and thus, will have longevity. I hold the designation Certified Technician (C.Tech.) with the Ontario Association of Computer Engineering Technicians and Technologists (OACETT), have been certified as a Professional Scrum Master level 1 (PSM I) and as a Professional Scrum Developer level 1 (PSD I) by Scrum.org as well as designated as an Officially Certified Qt Developer by the Qt Company. For more on my story check out the about page here

Feel free to write a reply or comment.