Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using cmake on windows for c++

Tags:

c++

cmake

for around 5 consecutive days i have been trying to set up my computer with the c++ environment for programming with libraries such as sdl,glm,opengl. its important for us to be able to run it on unix machines on presentations so im running with cmake. i finally got it to work with the cmake-gui, i wont even bother trying anymore with any IDE.

i specified my folder project and where to build the binaries, i got a folder "CMakeFiles" along with a txt "CMakeCache", a CMAKE file "cmake_install.cmake" and a file "Makefile". also in my folder "CMakeFiles" there are lots of other folders such as "CMakeTmp", "CompilerIdC", "CompilerIdCXX etc" and in both folders "Compiler*" has each an .exe which doesnt work! so where is my wanted executable?

i opened cmd and navigated to my folder and tried to write "make" as we are supposed to do according to the intruction. alas, it didnt work very well. hoping you could share your wisdom and help a newbie like me!

so what exactly is needed for compiling projects containing additional libraries? so far i have a compiler, Mingw32, the latest CMake and using the cmake-gui for extracting the binaries but gets makefiles.

EDIT: hrrm. is it only me who gets these kind of problems? i can add that i have look thorough about 10 tutorials and 90% of the steps are similar (if compiling with VS which i tried at first):

  • Download latest SDL
  • Make a folder on e.g C:\SDL with two folders, include and lib
  • Copy the libs and includes from the downloaded SDL
  • Make new VS project, open VC++ directories and add lib/incl folder on e.g C:\SDL
  • Add to linker SDL.lib and SDLmain.lib (i made sure they got linked, no problem here)
  • Change system to WINDOWS (optional if you dont want two windows)
  • Added include to "additional libraries"
  • Put the SDL.dll file (which i got from the latest SDL) in my C:\windows\system32(64SysWoW) and also in my project file.

so what i am actually looking for is gettning the CMake to work, since it generates and builds sources successfully (with the gui) and i feel im closing in. do i need to add any additional libraries from sdl to my compiler mingw32 and/or cmake?

like image 907
Yaman Baron Avatar asked Mar 26 '12 19:03

Yaman Baron


People also ask

Can you use CMake with C?

In the C/C++ ecosystem, the best tool for project configuration is CMake. CMake allows you to specify the build of a project, in files named CMakeLists. txt, with a simple syntax (much simpler than writing Makefiles).

Can I use CMake on Windows?

C++ CMake tools for Windows is installed as part of the Desktop development with C++ and Linux Development with C++ workloads. Both C++ CMake tools for Windows and Linux Development with C++ are required for cross-platform CMake development. For more information, see Install the C++ Linux workload in Visual Studio.

How do I run CMake on Windows 10?

Running CMake from the command line From the command line, cmake can be run as an interactive question and answer session or as a non-interactive program. To run in interactive mode, just pass the option “-i” to cmake. This will cause cmake to ask you to enter a value for each value in the cache file for the project.

Is CMake only for C++?

It is used in conjunction with native build environments such as Make, Qt Creator, Ninja, Android Studio, Apple's Xcode, and Microsoft Visual Studio. It has minimal dependencies, requiring only a C++ compiler on its own build system. CMake is distributed as open-source software under a permissive BSD-3-Clause license.


2 Answers

if you run cmake by command:

cmake -G "Visual Studio 14 Win64" path\to\source\dir

you need to run this command to continue(in Visual Studio Command Prompt):

msbuild Project.sln

either if you run cmake:

cmake -G "NMake Makefiles" path\to\source\dir

you need to run this cmd to continue(in Visual Studio Command Prompt):

nmake
like image 128
Protoss Avatar answered Sep 21 '22 20:09

Protoss


You were almost there with Visual Studio. Select Visual Studio as target. Open the generated project in Visual Studio, build it. (just like you alread did). Then, instead of trying to run BUILD_ALL, run a real project that creates an executable, it should also be in that list. Just right click it and 'play' it.

If you still get errors, post them in detail including what you did before the error. Note: a carefully configured cross platform CMake project (aka the CMakeLists.txt) should not require any fiddling with VC++ directories. It should work automagically, especially with well known libs such as SDL.

like image 39
Bob Avatar answered Sep 22 '22 20:09

Bob