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
Related
It seems like this should be easy and I've spent hours trying to find this answer online but haven't had any luck.
I can open the CLion folder path in Visual Studio, but that option doesn't give me the usual options to build and start the project. To do that, I need to open CLion as a Project/Solution, but I can't seem to do this.
My professor requires that my C++ code be executable in Visual Studio, but I prefer CLion. So I've done all my work in CLion and want to test that it runs in Visual Studio. How can I import my CLion project?
Thanks!
The link provided describes Visual Studio's CMake integration, which (similar to CLion) will install a version of CMake that Visual Studio will use. These instructions are pretty thorough and should provide everything needed to get your CMake project working in Visual Studio.
Now, you probably have two versions of CMake installed on your machine, one that came with CLion and one that came with Visual Studio. I would recommend installing the latest version of CMake on your machine separately, and configuring both Visual Studio and CLion to use that version instead. However, this is probably getting outside the scope of your immediate problem.
As you follow the Microsoft's instructions for "CMake projects in Visual Studio", you mentioned receiving the error:
1> [CMake] CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:173 (file):
1> [CMake] file failed to open for writing (No such file or directory):
This looks like a permissions issue, specifically while running CMake within Visual Studio, so be sure you have read/write access to all the files in your project, and the CMake packages in your Visual Studio installation. Hopefully, this doesn't require you re-install Visual Studio in another location on your machine, or run Visual Studio with elevated privileges, but perhaps that is necessary.
If you decide to install CMake separately, the instructions would be the following:
Install the latest CMake on your machine (somewhere you have adequate permissions), and ensure it is available in your Path environment variable. You can verify this by running cmake -version from the command line to see it is the version you just installed.
Using Windows command prompt, navigate to your CMake project directory (containing the top-level CMakeLists.txt file), and run the following:
mkdir build
cd build
cmake -G "Visual Studio 16 2019" -A x64 ..
You may run -A Win32 with the cmake command instead if your project is a 32-bit build.
Open the .sln Visual Studio Solution file that was generated in the build directory. Once, the Solution is loaded in Visual Studio, you can build the project (CTRL + SHIFT + B).
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
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.
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.
How can I force Cmake to use Visual Studio 2010 for compiling my emscripten projects, and now VS 2015?
I keep running into an issue where cmake says it cannot find the build tools for MSBuild v140. I know it exists though, as the file path is
C:\Program Files (x86)\MSBuild\14.0\Bin
I've even tried setting the path in the Emscripten Command Prompt with
set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%
but the issue still occurs.
If I open this solution in VS 2015, I can see that the configuration is set to Msbuild v 1.40, so I can't wrap my head around why Emscripten says it can't locate it.
The closest thing I could find is in this GitHub bug report on Emscripten.
Any suggestions?
Emscripten in Visual Studio is only supported for VS2010 AFAIK. Personally, I suggest you work with makefiles when generating from CMake. It is much more stable from my experience. The Visual Studio support for Emscripten is not working well, at least for me.
But if you still want to use VS2010, then you have to set the CMake generator to "Visual Studio 10 2010", and then specify the Emscripten toolchain file. You might have to set the CMake platform name to Emscripten, using the -A argument.
cmake.exe -G "Visual Studio 10 2010" -A Emscripten -DCMAKE_TOOLCHAIN_FILE=%EMSCRIPTEN%\cmake\Modules\Platform\Emscripten.cmake
I tried doing this, but each time I did, Emscripten would return a different path to Emscripten.cmake, and say it couldn't find it. Not sure where it was getting this new path from.
Long story short, I realized I installed the web installer for Emscripten installed. So I uninstalled that and instead went with the Full installer, and it all worked well.