Categories: Windows

A very beginner for Visual C++ with CMake.

   Yesterday, I installed Visual Studio Community 2017 for learning Visual C++ with CMake. Why did I decide to learn Visual C++? Because I want to compile Apache Dev version for Microsoft Windows. The page says httpd can be built on Windows using a cmake-based build system. Besides, Visual C++ Team says they can support CMake in Visual Studio 2017 easily and CMake Team does CMake version 3.7 or higher are compatible with Visual Studio 2017. The time is very good. I decided to learn Visual C++ with CMake.

[About Visual Studio 2017]
   First, download Visual Studio Community 2017 from the site. About installing, see Install Visual Studio 2017. At Step 4 – Select workloads, I checked all check boxes because I don’t know what I need exactly. VS 2017 system Requirements is here.
   The installation takes several time though it depends on your environment. Be patient.

   When you run Visual Studio Community 2017 for the first time, it suggests you sign in to Visual Studio and you need it because Unlocks the Visual Studio Community Edition instead of being limited to the trial period of 30 days.

[About CMake]
   Second, download CMake from the site. Choose the file you need. In my case, cmake-x.x.x-win32-x86.msi. Click the msi file to install. At Install Options dialog, choose “Add CMake to the system PATH for all users” or “Add CMake to the system PATH for the current user”.
———————
   Now I have VS 2017 and CMake on my PC.
   Build HelloWorld.exe for checking I have proper installations or not. I do all in Visual Studio.

  1. Run Visual Studio 2017 from Desktop icon.
  2. To create HelloWorld app, on the menu bar, choose File, New, Project. Like this.
  3. In the Visual C++ category, choose the Win32 Console Application template, and then name the project HelloWorld.
  4. In the HelloWorld.cpp file, enter a blank line before the line return 0; and then enter the following code:
    printf("Hello, World.n");

   At the point, I can get HelloWorld.exe without CMake. But I need CMake. So, I add a CMakeLists.txt file to the directory that includes the HelloWorld.cpp file.

  1. At Solution Explorer, change View from Solution to Folder. Like this.
  2. Right click HelloWorld folder and add a new file. Change the file name from New File to CMakeLists.txt.
  3. In the CMakeLists.txt file, enter the following code:
    add_executable(HelloWorld HelloWorld.cpp)
    Now I have CMake(K) on the Menu bar.
  4. I right click the CMakeLists.txt file at Solution Explorer and build HelloWorld.exe with CMake. See fig.07.
  5. I select HelloWorld.exe in the Startup Item dropdown in the General toolbar and launch the debugger. See fig.08 and fig.09.
  6. The execute time of HelloWorld.exe is veeeeeeeeeeeeeeeeeeeeery short. So I cannot see “Hello, World.” in the cmd window if I set a Break Point at the line return 0;. Any way, I have HelloWorld.exe. I’m happy.

   My goal is still a long way off, though.

o6asan

Recent Posts

Very easy, sweet potato yōkan recipe.

The recipe for sweet potato yōkan that I often made this fall. Ingredients Sweet potato…

5 months ago

On my home network, I’ve built an FTP server that I left for long time.

After a long time, when I checked broken links and fixed them, I got an…

2 years ago

Moving “o6asan’s BBS”.-#2

I made a box, so I prepare the contents. Theme and Plugins. The theme is…

2 years ago

Moving “o6asan’s BBS”.

Hehe, it's been almost a year since my last post. I received a notification email…

2 years ago

I completed my WordPress to Sub-domain.

About a week ago, I finally started to renew my sites, which I had been…

3 years ago

Happy New Year!

   Happy New Year! It is the beginning of a new year.    This is a year…

5 years ago

This website uses cookies.