Kluge to get Qt to work with CUDA v9.2.. must be a better way
I wanted to share a kluge I had to do in order to get Qt to work with the latest CUDA toolkit on windows, and also ask if there is a better way (and surely there is). The problem is this - the latest CUDA v.9.2 toolkit does not work with _MSV_VER > 1913. So if you install Visual Studio (and I have the latest version of VS Professional) ultimately it means that cl, the command line compiler that Qt calls, will have a version > this. You can install an older version of Visual Studio in parallel via the MS installation tool, but the default version of cl will be the latest version (1914 at the time of this writing).
The official way of getting cl to run on the command line is to call a file called vcvarsall.bat, which on my machine resides in Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Build\vcvarsall.bat. When called with no argument, cl will then run from the environment (be it command prompt or whatever else) with the latest version. If you wish to run an older version of cl, all you have to do is call vcvarsall.bat with an argument such as:
If you call the .bat file this way, then cl will run with _MSV_VER = 1913 and everything works. (Including nvcc).
So here's where the horrible kluge comes in. All I needed to do to get everything to work is to get Qt to call the .bat file with this correct argument. But I cannot for the life of me figure out how to do this. So finally I was reduced to changing this critical VS file to being editable, and manually editing it to force it to always insert this argument!! Fortunately it seems the .bat file is set up in a way that makes it easy to do this. All you have to do is edit this line at the start and set __VCVARSALL_VER=14.13.26128
I am sure you're not really supposed to do this and Visual studio is now broken, which is OK since I'm just using Qt for my build. But this did get (so far) Qt to work with nvcc and CUDA and things seem OK.
So hopefully this is useful for people since it took me some time to determine how to do this. But also maybe someone knows what to do to get Qt to call this .bat file, which it must be doing at some point, with the correct argument. I cannot even figure out what part of Qt even calls this .bat file. It's not in any of the Qt scripts that I can see.
Hi and welcome to devnet,
Thanks for sharing this !
Building something with CUDA is always a bit hard because of the set of compilers/linker they support that not always match whats current or available (thinking also about the unix platforms) as you have found. It's not something that Qt can directly do much about.
As for setting up the environment, do you mean by Qt Creator to handle your project ?
Thanks for the reply. By "Setting up the environment" I mean that at some point, I would assume, Qt calls vcvarsall.bat. Further it passes the argument amd_x86 or something. If I could just figure out how to alter this, that is the cleanest way to enable CUDA - then I can just pass the correct argument to the vcvarsall.bat. Perhaps the call comes within qmake. I cannot find any information in any of the configuration files as to how it decides to call vcvarsall.bat and with which arguments.
VRonin last edited by VRonin
I mean that at some point, I would assume, Qt calls vcvarsall.bat.
It does not. If you call qtenv2.bat it will make it very clear that it's your responsibility to manually call
Qt Creator does (tools->option->compilers->select an msvc compiler-> Initialization) but I'm not aware of any option to override the arguments passed to vcvarsall
You are right - and I should have been more precise. I meant Qt creator when I said Qt.
If indeed there is no way to modify Qt creator to call vcvarsall.bat with different arguments then my horrible kluge is in fact the only way to get CUDA to work on some systems!
Fortunately it does work just fine with the above kluge.
Qt Creator is open source, you can modify it at will.
What @VRonin meant is that the current version of Qt Creator doesn't provide such an option.
You might want to open a feature request for it.