CMAKE: "No CMAKE_CXX_COMPILER could be found." - c++

I have a simple project where the file structure looks like this:
- CMakeLists.txt
- main.cpp
The CMakeLists.txtlooks like this:
# Project initialization
cmake_minimum_required (VERSION 2.6)
project (Tutorial)
add_executable(Tutorial main.cpp)
When I run the Cmake GUI I get:
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_CXX_COMPILER could be found.
I have Microsoft Visual Studio 2017 installed. I have compiled and run apps from it. The basic example from the CMAKE tutorial does not work.
Can anyone tell me why?

I'm not sure what is going wrong but you might want to take a look at:
https://learn.microsoft.com/en-us/cpp/ide/cmake-tools-for-visual-cpp?view=vs-2017
Visual Studio 2017 is able to open cmake files directly (should do the generator step for you behind the scenes) which may avoid the problem you have.

Use the integrated Visual Studio CMAKE.
The error reporting in the VS build/output/error window has become somewhat complex, and many errors are delegated between the toolchains, etc. (i.e. the whole VS has become modularized lately)
Universal truth: log files are your best friend.
In my case,
CMakeError.log has been constantly complaining it can't find kernel32.lib
Guess what? I forgot to install Windows SDK.
Basically, for any serious work, you need at least MSVS and Windows SDK, if you want to build for Windows. (Windows SDK is also now known as "Windows Kits", which is what you'll get in the StartMenu).
Essentially, your problem might simply be you don't have proper dev libs installed.

Related

Visual Studio 2022 not showing any CMake Targets

I was having this issue with a much larger project but I reproduced it with a quickly throw together example. Visual Studio correctly generates everything using CMake, and if I then go to the toolbar and select Build -> Build All it will successfully compile and link everything, and I can run the resulting executables from powershell... The Output from CMake is shown to be this:
According to the Visual Studio CMake documentation I should see an additional line stating: Target info extraction done.. I believe that is the core of my issue, but I am unsure why it is not occurring as everything else seems to work fine.
If I try to run (or debug) anything from Visual Studio itself, it simply says I need to select a "Startup Item", but none are available:
Looking at Visual Studio CMake documentation here, I should be able to simply go to the CMake Targets View in the solution explorer, and see all of my targets, but I do not see any:
While I should see (in this very simply example) a target for hello, given I have the following CMake structure:
Root CMakeLsits.txt file:
cmake_minimum_required(VERSION 3.9)
project(vira LANGUAGES CXX VERSION 0.9)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
add_subdirectory(src)
src/CMakeLists.txt:
add_executable(hello hello.cpp)
src/hello.cpp:
#include <iostream>
int main()
{
std::cout << "hello world!\n";
return 0;
}
I have been driven crazy by this as the people I've asked about it have simply reiterated what the Visual Studio documentation says, yet neither for this simple project, nor the larger actual project I've been working on, do any CMake targets ever show up. Meaning I'm unable to use any of the debugging features of Visual Studio, since I cannot select a startup item.
Am I doing anything incorrectly? Visual Studio clearly at least recognizes the CMakeLists.txt as it automatically generates everything, and will Build the project if I manually go to Build -> Build All. That has me even more confused as to why I'm experiencing this.
I have attempted even reinstalling Visual Studio from scratch, yet nothing has helped.

Linking errors in Poco with Conan package manage on Windows [duplicate]

I have a project which i have generated with cmake and running in visual studio 2010.I changed the configuration to x64,in visual studio my active solution and the Target Machine in(Properties->Linker->Advanced) is set as x64.I still get the linker LNK1112 error.Is this something which i set in cmakelist.txt if so what is the command?
-swetha
It's not something you'd want to set in CMakeLists.txt. Basically, CMake has multiple generators for different compilers. (The x86 and x64 compilers are two distinct compilers on Windows.) When you generate the build files, you need to pass along the correct compiler for CMake to use, or if you use the GUI, select Win64. From the command line:
cmake -G "Visual Studio 14 Win64" path/to/your/CMakeLists.txt
or whatever version of Visual Studio you want. You can see the available generators with:
cmake --help
If this didn't solve your problem, try it again after deleting the generated build files.
If that still doesn't solve the issue, you are linking to a third party dependency built for x86.
Try to delete all *.obj files in your solution and let compiler compile all files again. This problem may cause of compiler try to reference obj files that was compiled x64

Link cmake to visual studio's cmake tools

Im sorry for the bad title but I just don't know how to put this in the title, so if you do, please remove this line and update the title.
So Im trying to create a portable version of cmake (that doesnt needs admin rights) and I found this but the awnser only helped me getting cmake itself in a different location. Cmake also needs MSVS's (Microsoft Visual Studio's) Cmake tools to get it to work.
My question is where are these tools located, and can I copy them to a USB stick and make it so cmake uses the tools on the usb stick?
I thought that maybe I could make a batch file that sets a local variable to the tools on the usb stick and then start cmake so cmake knows where the tools are located, but I don't know if cmake even uses Environment Variables.
Any help would be greatly appreaciated, thanks
There are multiple points in your question that are unclear.
Portable CMake
With downloading the ZIP file of CMake you already "made CMake portable". Just unzip and run it.
CMake has an internal logic to detect installed Visual Studio versions and the compiler.
CMake Variants
Original
To use CMake with the MSVC compiler (or provided by Visual Studio) you do not need anything special from MSVC/VS. CMake uses the informations of the detected MSVC/Visual Studio to generate the project files, etc.
Visual Studio's CMake Variant
Visual Studio provides a version of CMake upon installation. To use your portable CMake variant you do not need anything from there.
Force a specific VS Generator
If you have only one Visual Studio installed then CMake will use this. If you have multiple Visual Studios installed normally CMake uses the newest one. In case you want to force a specific Version you can specifiy the CMake generator to use cmake-generators.
Another way would be to use the vcvarsall.bat or vsdevcmd.bat to setup the environment for a specific Visual Studio version and run CMake from that environment.
Finally
It is sufficient to have the original CMake release (from the ZIP file) on your USB stick. But it is not possible to provide a portable MSVC (Microsoft Visual Compiler) on your USB stick (as far as I know) as it has to be installed.

Cmake boost looking for wrong architecture type [duplicate]

So I've been looking around in stackoverflow and some other forums how to force CMake to look for the x64 libraries instead of x32 and it didn't really help much.
When I do:
find_package(Boost
1.67.0
COMPONENTS
atomic
REQUIRED
)
for some reason CMake looks for the x32 libraries instead of the x64 ones and fails to find them. I know this by adding this option in the cmake command:
-DBoost_DEBUG=ON
Which shows me this(It shows of course more than what I posted, but I posted the important lines):
_boost_LIBRARY_SEARCH_DIRS_RELEASE = C:/develop/libraries/boost/1.67.0/x64-vc141/Release/lib
Searching for ATOMIC_LIBRARY_RELEASE: boost_atomic-vc141-mt-x32-1_67;boost_atomic-vc141-mt;boost_atomic-vc140-mt-x32-1_67;boost_atomic-vc140-mt;boost_atomic-mt-x32-1_67;boost_atomic-mt;boost_atomic
But instead of looking for this:
boost_atomic-vc141-mt-x32-1_67
Which is obvious why it can't find it.
I want it to look for this:
boost_atomic-vc141-mt-x64-1_67
What am I missing? is there some extra CMake configuration I suppose to add in order to make CMake understand that I'm using boost for x64 architecture?
I even tried to start Developer Command Prompt for VS 17 in x64 mode the manual way by calling:
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64
Thanks in advance for the help!
When you generate anything with CMake you should specify a generator unless the default one suites your needs. Looks like in your case the default one (whatever it is) doesn't work for you so you should provide it like this (for MSVS 2015):
cmake -G "Visual Studio 14 2015 Win64"
Note the architecture in the generator it is important for the search. Later you can build it with the CMake --build but you still have to generate some make files which are using x64 compiler.

How to compile opencv with visual studio without CMake

I want to compile opencv with visual studio, so the code of opencv will be on my computer like all other local code. i.e. i want to be able to change it and debug it.
I can't find anywhere a simple directory file with all the opencv files. It is segmented into include files, modules and similar.
All explanations in the opencv documentations use CMake.
I don't understand what exactly is CMake and why would I need it in order to compile the library locally just like all other regular code.
Can anybody explain me how to do this?
cmake is an platform independent makefile. You can generate from cmake also visual studio projects, which can than imported into visual studio. But you need to install cmake on your computer.
To make a visual studio project call cmake like this:
cmake -G "Visual Studio 9 2008"
Cmake Wiki