CMake and Visual Studio with not default installation folder - visual-studio

I am trying to build something using CMake and VS 2012. The problem is I have my VS installation on D:\Pliki programów (x86)\Microsoft Visual Studio 11.0. I have no free space on my C drive.
CMake have problem with finding my VS. I tried to specify VS compiler cl.exe but it was asking for dll in the same folder anyway. I also tried to use specified toolchaing with vcvarsall.bat. But I am not sure if I am doing those things right.
I guess that I need to add VS location to CMake, but how? I tried setting PATH but it did not work.
And searching about that problem is difficult, all search engines think that I want to change installation path for my program that I want to build.
UPDATE
I've added variable_watch(CMAKE_MAKE_PROGRAM).
CMake Debug Log at CMakeLists.txt:3 (project):
Variable "CMAKE_MAKE_PROGRAM" was accessed using UNKNOWN_READ_ACCESS with
value .
CMake Debug Log at CMakeLists.txt:3 (project):
Variable "CMAKE_MAKE_PROGRAM" was accessed using MODIFIED_ACCESS with value
C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe.
The C compiler identification is unknown
The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
In output file:
LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib'
Is CMake looking for libs in VS 11 installation folder? The thing is that VS installer put libs in C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64.

For cases like this (and similar), I keep a VCEnvCmd.bat in my source trees:
call "%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat" amd64 & %*
Executing that .bat without parameters will find and run vcvarsall.bat, setting up the environment for the amd64 target in the current shell (which you could change or parameterize according to your needs, like the version number embedded in that environment variable).
The nice trick is, for those Nightly / Continuous builds, you can use the .bat as a "prefix" for setting up the environment, e.g. in the task manager:
VCEnvCmd.bat ctest -S CTestScript.cmake,Nightly
The advantage is that you use what MSVC already gives you (the VS...COMNTOOLS variable), without having to clutter your environment further with persistent changes to PATH etc.

Related

2020: nvcc fatal : Cannot find compiler 'cl.exe' in PATH

I'm trying to run StyleGan2 by Nvidia. I have created a new enviroment, I failed this check mandated in the readme file provided.
In particular, when I run it, I get the error you see in the title of the question. I looked it up, and the solution ostensibly is to add this path to env vars
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin
I'm trying to do that, but I don't have bin in my VC folder! I only have include and lib, brand new installation of visual studio.
Thanks to #talonmies, the solution is as follows:
Firstly, c++ package doesn't come by default with a clean new installation of VS, you need to select the package.
Secondly, it seems that now the path for cl.exe is here
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x64
In my case the full error message was:
nvcc fatal : Cannot find compiler 'cl.exe' in PATH
...
No CMAKE_CUDA_COMPILER could be found.
Tell CMake where to find the compiler by setting either the
environment variable "CUDACXX" or the CMake cache entry
CMAKE_CUDA_COMPILER to the full path to the compiler, or to the
compiler name if it is in the PATH.
So I had to do:
export CUDACXX="/mnt/c/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe"
and it worked.

What is the -D define to tell CMake where to find nmake?

I have Visual C++ Build Tools 2015 | Standalone compiler, libraries and scripts installed on a low-end netbook. It's necessary, because the machine has a small eMMC soldered to the board with no real space available.
nmake is installed at %PROGRAM FILES%\Microsoft Visual Studio 14.0\VC\bin. However, CMake cannot find it when attempting to generate the Makefile. I'd like to use a -D to tell CMake what the makefile program is, but I am having trouble locating the list of -D defines for CMake.
For completeness, I'm trying to avoid other Microsoft tools. I have LLVM build tools at C:\LLVM\bin, so I'm setting CMAKE_C_COMPILER and CMAKE_CXX_COMPILER. But I needed nmake, because I can't find a stand-alone Make program for Windows already built.
What is the -D define to specify nmake for CMake?
The variable you are looking for is CMAKE_MAKE_PROGRAM.
If you try to set this variable plus CMAKE_C_COMPILER, CMAKE_LINKER_EXE, etc., this will still fail, because cl.exe and link.exe need some environment variables to be set. Those can be set by using a "Visual Studio * Command Prompt" (this uses vcvars.bat from the Visual Studio install directory).
To use Clang you can install a Clang toolset from http://llvm.org/builds/. Then you can specify CMAKE_GENERATOR_TOOLSET in a toolchain file.
Let me know how this works out for you.
CMAKE_MAKE_PROGRAM. See the documentation:

Linking errors with boost, VS2010, and CMake

I have searched high and low for this answer. I have tried suggestions to similar problems posted on Stack and other sites. My toolchain consists of an x64 machine with windows 7, visual studio 2010, opencv 2.4, qt 4.8, and boost. I configure all of my projects using CMake, which finds all of these libraries and includes and creates my visual studio project. I have compiled two versions of boost, a 32-bit version build in the command line and placed in \boost\boost_1_47_0\lib\win32, and a 64-bit compiled in the Windows SDK v7.1 64-bit compiler and stored in \boost\boost_1_47_0\lib\x64. Everything in the project compiles fine with the exception of boost. I get a compiler error:
fatal error LNK1104: cannot open file 'libboost_filesystem-vc100-mt-1_47.lib'
As a reminder, CMake is handling all of my linking and it properly locates this lib and adds it to the visual studio project. I can verify this by looking at Properties->Linker->Command Line. Here, in addition to files representing other libraries, it has listed:
"C:\Tools\boost\boost_1_47_0\lib\x64\boost_filesystem-vc100-mt-1_47.lib"
"C:\Tools\boost\boost_1_47_0\lib\x64\boost_program_options-vc100-mt-1_47.lib"
"C:\Tools\boost\boost_1_47_0\lib\x64\boost_date_time-vc100-mt-1_47.lib"
"C:\Tools\boost\boost_1_47_0\lib\x64\boost_thread-vc100-mt-1_47.lib"
I can suppress this error by manually adding my boost\boost_1_47_0\lib\x64 directory to Properties->Linker->General->Additional Library Dependencies. This compiles without error. However, when I go to run the application, I am met with a system error that tells me:
The program can't start because boost_filesystem-vc100-mt-1_47.dll is missing from your computer. Try reinstalling the program to fix this problem.
In this /x64 directory I have:
boost_filesystem-vc100-mt-1_47.dll
boost_filesystem-vc100-mt-1_47.lib
libboost_filesystem-vc-100-mt-1_47.dll
Any insight would be incredibly appreciated. Thanks!
To solve the runtime error:
Add the location of the dll(s) to the PATH environment variable.
For example on my machine:
set PATH=%PATH%;c:\users\chris\boost_regex-vc140.1.63.0.0\lib\native\address-model-32\lib
or copy the dll(s) to a directory already in the PATH
See here: https://msdn.microsoft.com/en-us/library/7d83bc18.aspx?f=255&MSPPError=-2147217396

Running vcvars32.bat before compiling in Code::Blocks?

I've installed Visual Studio C++ Express 2012 and want to use it's compiler with Code::Blocks. Starting cl.exe does not work (missing mspdb100.dll) until I run vcvars32.bat, but that does only hold on for the current session in the Command-line. The same applies to compiling with Code::Blocks.
How can I make it run the vcvars32.bat before compiling?
Workaround
That workaround is actually not what I was looking for, but it works, and that is important. Instead of letting Code::Blocks running cl.exe directly, I've set-up a simple batch-script that runs vcvars32.bat before running the actual compiler.
REM File: cl.bat
call vcvars32.bat
call cl.exe %1 %*
In the project properties, you have a section Build events. You can add vcvars32.bat to the pre-build event.
To run the .bat before compiling in Code Blocks(16.01), go to the project build options and its under the "pre/post build steps" tab. This tab only appears in the project settings, not the compiler settings.
However, adding "vcvars32.bat" (or "vcvars64.bat") to the pre build steps didn't fix the error for me.
I found the directory where the library is and added it to the linker search directories. This gave errors about further missing libraries. I added the following paths to my linker settings. These will almost certainly be different for you. I'm installed MSVS 2017 community edition. For some reason known only to Microsoft, the necessary libraries are installed on two different drives.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\lib
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\lib\x64
D:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x64
D:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\ucrt\x64
Note that the .bat script is no longer necessary if you add these paths by hand.

Building Qt for Visual Studio 2010 - cannot open file 'qtmaind.lib'

I'm trying to start a C++ Qt application and have it run and compile in Visual Studio 2010.
Doing some googling, I found that there was a Visual Studio Qt Add-in, and so I installed this. I already had a MinGW Qt binary installed, and when this did not work, I found that you have to compile the source for Visual Studio 2010 (the VS 2008 binary will cause deployment issues).
Using this as a guide: How to build Qt for Visual Studio 2010, I compiled the open source version, and added it to the PATH, along with a QTDIR env variable. Hoping that I got it finally working, I created a "Qt Application" using the New Project Wizard in Visual Studio 2010. Once I finished, I tried to build the program, only to see the following error:
1>LINK : fatal error LNK1104: cannot open file 'qtmaind.lib'
I looked in the C:\QT\lib folder, and found that I only have a qtmaind.prl, but no clue as to why there is no qtmaind.lib.
I am able to echo the QMAKESPEC environmental variable to get a 'win32-msvc2010' output.
I've tried several different combinations of flags for the configure step, including the one in the link, and even tried manually setting the -platform flag.
If anyone can offer any help, it would be greatly appreciated! :D
Just ran across this same problem. I changed the "-release" flag from the linked guide to "-debug-and-release", and then it built the qtmaind.lib library (presumably, that "d" suffix stands for debug).
I encountered this issue when running a project whose settings were hardcoded for a particular machine setup.
I could see that the vcxproj file had something like:
C:\Qt\4.8.1\libqtmaind.lib
I could not find this lib file in my machine. I replaced the line by:
C:\Qt\4.7.3\lib\Qtmaind.lib
It looks like the names of library files are different across Qt versions.Or, maybe the library files were renamed.
Also, the 'd' denoted debug. If you cannot find any lib file post-fixed by 'd', it is likely that you did not 'make' a debug version of Qt.
You can cross check this by opening the .Sln file created by configure. Mine was named Projects.sln. You can open this in notepad and see if win32-debug configurations are present.
This might be a QMAKESPEC issue. Try setting your QMAKESPEC environment variable to
win32-msvc2010
and rebuild Qt like that. This should give you .lib files in your Qt folder
in QT 5.3 with vs 2013
in properties -> linker -> input
remove ANY path for qt libraries such qtmaind.lib
this is known BUG

Resources