MinGW installation and environment variable configuration and Sublime Text 2 to build a C++ compilation environment

MinGW installation and environment variable configuration

Download MinGW from http://sourceforge.net/projects/mingw/ and install it to D:\MinGW. Toolset selection installation (can also be installed and uninstalled later): At least mingw32-base, mingw32-gcc-g++, msys-base toolsets need to be installed.

 

After the installation is complete, you need to configure the environment variables:

Right click My Computer, click Properties->Advanced->Environment Variables. Then in the user variable column:
  1. Add D:\MinGW\bin to the PATH. If there are other variables in it, remember to add a semicolon. The semicolon must be entered in English input mode. If there is no PATH, create a new PATH variable.
  2. Create a new LIBRARY_PATH variable, if any, add D:\MinGW\lib to the value, which is the location of the standard library.
  3. Create a new C_INCLUDE_PATH variable and set the value to D:\MinGW\include.

The environment variables have been configured, we open a CMD window to verify and see if our environment variables have been configured successfully. Enter gcc -v under cmd

 

If the gcc version can be displayed, the MinGW installation and configuration is successful.

Sublime Text 2 builds a C++ compilation environment

Open Sublime Text 2, select Tools--"Build System--"New Build System, and enter the following code in it:
[plain]  view plain copy  
 
  1. {  
  2.     "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],  
  3.     "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",  
  4.     "working_dir": "${file_path}",  
  5.     "selector": "source.c, source.c++",  
  6.   
  7.     "variants":  
  8.     [  
  9.         {  
  10.             "name": "Run",  
  11.             "shell": true,   
  12.             "cmd" : ["start", "cmd", "/k", "${file_path}/${file_base_name} &&echo. & pause && exit"]    
  13.         }  
  14.     ]  
  15. }  


Then save it as: C++builder.sublime-build, note that the suffix must be sublime-build. If you don't want to create a new build system, you can directly modify the C++.sublime-build file in the saved directory, and also change it to the above code.

 

test

Create a new a.cpp in Sublime and write the code:
[cpp]  view plain copy  
 
  1. #include<iostream>  
  2. #include<string>  
  3. using namespace std;  
  4.   
  5. int main(){  
  6.     string b="hello world!";  
  7.     cout<<b<<endl;  
  8.     return 0;  
  9. }  
Select Tools--"Build System--"Select the newly created compilation system, press Ctrl+B to compile the program to generate a.exe; then Ctrl+Shift+B to run the program, the result is as follows:
hello world!
Please press any key to continue...

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325345156&siteId=291194637