WINDOWS+CMAKE+MINGW Building C C + + development environment

Source: Internet
Author: User
Tags posix

Layout:post
Title: "Windows+cmake+mingw build C C + + development environment"
Date:2018-03-30 22:23:06
Tags:windows CMake MinGW/C + +
key:201803302223
Description: This article teaches you how to use CMake and MinGW in a Windows environment to build a C + + development environment that is as experienced as Linux development
---

CMake installation CMake Download

Official: https://cmake.org/download/

Select the corresponding version of your system (Platform) and download
Here we choose the Windows win64-x64 Installer:installer tool has changed. Uninstall CMake 3.4 or lower first!

CMake Installation

During installation, depending on your system's security settings, you may see the following dialog box, do not worry, directly click "Run (R)"

Consent must be chosen, otherwise the next step cannot be entered

    • Whether or not to add environment variables, here we select "Add CMake to the system PATH for all users"
    • Whether to create a desktop shortcut icon, according to their own circumstances, this is just to create desktop icons easy to use, and will not have a substantial impact on future use
Installation path

Here you choose the path where you are accustomed to store the program, we take the default value here

Installation Final Confirmation

After the previous operation has finally configured the need to configure, the following program to work on their own

Enter the installation

Really start the installation phase, this phase is more time-consuming, completely depends on the configuration of the computer itself, the system is mainly to extract files and write disk

Installation Complete

Congratulations, the CMake installation is finally complete.

Confirm CMake Installation

Verify that the CMake is installed successfully, you can bring up the cmd window, enter cmake , see what the system will say to you, if the following window appears, then congratulations you do not have any problems.

So what if the following is the case?

We generally have the following processing steps and processing methods:

      1. Confirm that the new CMD window is being paged again
      1. We can manually modify the system's environment variables to specify the bin directory location of the CMake


Confirm that the content is configured in path, if it is not manually entered and determined

      1. After 2 operations can be re-verified, if resolved so congratulations, if the problem persists, then need to restart the system (generally can be resolved, unless the lower version of the system may require a restart)
Mingwmingw Download

This gives the mingw used by the 64 system, https://sourceforge.net/projects/mingw-w64/

Here is actually the download of an installer, the specific installation is by running this installer to boot the installation

MinGW Installation

MinGW installation Options

There is a need to make the appropriate choice, of course, there is absolutely no problem, we use the default, continue to install

MinGW Mounting Position

There's a pit, we're going to go into the pit and continue the installation.

MinGW in Installation

The installer needs to download the required files from the Internet, which takes a long time

MinGW Installation Complete

environment variable Settings

As with CMake, MinGW automatically sets the environment variable after installation, and you can run the environment by running its installation directory. mingw-w64.bat

Verify that the MINGW environment is set up, the same new CMD window, enter the gcc command, access to the following information indicates that there is no problem, otherwise please refer to the CMake configuration environment variable way to resolve.

Cmake+mingw instances

After we install the environment, we'll run the next instance.

    • Writing source files
      Let's go to the most famous program in the universe.
#include <stdio.h>int main(){    printf("hello\n");        return 0;}
    • Writing CMake files
cmake_minimum_required(VERSION 3.0)project(Hello)set(SOURCE main.cpp)add_executable(${PROJECT_NAME} ${SOURCE})
    • Generate Make File
mkdir buildcd buildcmake -G"Unix Makefiles" ../

Unfortunately, this step is going to be a problem.

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.CMake Error: CMAKE_C_COMPILER not set, after EnableLanguageCMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage-- Configuring incomplete, errors occurred!See also "D:/tmp/build/CMakeFiles/CMakeOutput.log".

This means that you cannot generate UNIX makefiles, which is caused by the lack of make programs,
The solution is to find a copy of Mingw32-make.exe in the MinGW installation directory and rename it to Make.exe

Run againcmake -G"Unix Makefiles" ../

$ cmake-g "Unix makefiles". /--The C compiler identification is GNU 7.2.0--The CXX compiler identification are GNU 7.2.0--Check for working C Compil Er:c:/program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gcc.exe--Check for working C Compiler:c:/program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gcc.exe--works-- Detecting C compiler ABI info--detecting C compiler ABI info-done--detecting C compile features--detecting C compile features-done--Check for working CXX Compiler:c:/program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/ mingw32/bin/c++.exe--Check for working CXX Compiler:c:/program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_ V5-rev1/mingw32/bin/c++.exe--works--detecting CXX compiler ABI info--detecting CXX compiler Abi info-done--detectin G CXX compile features--detecting CXX compile features-done--configuring done--generating done--Build files have bee N Written To:d:/tmp/build

That's right.

    • Compile
make

What, there's a problem.

$ make/usr/bin/sh: -c: line 0: syntax error near unexpected token `('/usr/bin/sh: -c: line 0: `C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/make -f CMakeFiles/Makefile2 all'make: *** [Makefile:84: all] Error 1

Remember the front we installed MinGW said pit, now we need to pits, file is all Evil C:/Program Files (x86) , this is good to do, copy the mingw-w64 folder to a normal directory, such as direct C:/mingw-w64 , and then need to modify the environment variables

$ makeScanning dependencies of target Hello[ 50%] Building CXX object CMakeFiles/Hello.dir/main.cpp.obj[100%] Linking CXX executable Hello.exe[100%] Built target Hello
    • Run
$ ./Hello.exehello

All right, it's finally done.

WINDOWS+CMAKE+MINGW Building C C + + development environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.