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
- {
- "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
- "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
- "working_dir": "${file_path}",
- "selector": "source.c, source.c++",
- "variants":
- [
- {
- "name": "Run",
- "shell": true,
- "cmd" : ["start", "cmd", "/k", "${file_path}/${file_base_name} &&echo. & pause && exit"]
- }
- ]
- }
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
- #include<iostream>
- #include<string>
- using namespace std;
- int main(){
- string b="hello world!";
- cout<<b<<endl;
- return 0;
- }