C ++ environment setup for beginners (eclipse + CDT + mingw)
In addition to Java Development, eclipse also supports many languages. Of course, C/C ++ will never be missed, now let's take a look at how to use eclipse to develop C/C ++ programs.
The main steps to use eclipse to develop C/C ++ programs are as follows:
1. Install JRE
Because eclipse is developed in Java, JRE is required.
2. Install eclipse
3. Attach CDT
4. Install mingw
This is to make your computer have GCC, G ++ Compiler
Detailed installation steps:
1. Install JRE 5.0
‧ Download page: http://java.sun.com/j2se/1.5.0/download.jsp
‧ Click Download JRE 5.0 Update 5, click accept, and then select Window platform "Windows offline installation, multi-language"
‧ Download and install it.
Ii. Install eclipse
First go to the eclipse official website http://eclipse.org left bar to find download currently 3.3 Europ version has been release. After the download, decompress the package to the desired path and pull out the shortcut without installation. Of course, we also directly download eclipse-cpp-europa-fall-win32.zip, saving step 3 J.
3. Attach CDT
Next, to enable eclipse to develop C/C ++ programs, you need to attach CDT. First download the CDT. Download the URLHttp://www.eclipse.org/cdt/find cdt-master-4.0.1.zip
Install: copy the decompressed features and plugins to the eclipse installation data folder.
To restart eclipse.
When creating a new project, you can see that the C and C ++ options are available, which indicates that the installation is successful.
If you cannot see it, add the-clean command.
4. Install mingw
So far, CDT has been installed for Eclipse, but a "Compilation Program" is required to compile the program.
Therefore, you need to download the gnu c, C ++ compilation programs that can be used on Windows. here you need to download the mingw program.
Download URL: http://www.mingw.org/download.shtml#hdr6
Find MinGW-5.1.3.exe on the download page
PS:
Install: Select "C" for the installation directory, and click "Next. After installation, the path is like this-> C: "mingw.
Add the following settings to the environment variables:
Path: C:/"mingw" bin;
For Windows users, choose "edit" from "My Computer" system variable ">" path"
Add C:/"mingw"/bin; at the beginning.
Because the default file named make.exe is used for compilation in eclipse, but after mingw is installed, the default make extension name is mingw32-make.exe.
So you can rename the mingw32-make to make!
To enable CDT to use mingw for compilation, we need to go back to eclipse to set
Window-> preferences-> C/C ++-> New CDT Project Wizard-> makefile Project
Locate binary parser, cancel elf parser, and select PE windows parser.
5. Install GDB
GDB is a powerful debugger used to debug C and C ++ programs. it enables you to observe the internal structure and memory usage of the program while the program is running. the following are some functions provided by GDB:
- It enables you to monitor the value of variables in your program.
- It enables you to set breakpoints so that the program stops running on the specified code line.
- It enables you to execute your code in one row.
The latest version of wingw does not provide the gdb tool. Therefore, we need to download it separately at http://www.gnu.org/software/gdb/download/download gdb-5.2.1-1.exe
And install it to the C:/mingw/location.
All installation has been completed.
Next we will try to write a small program.
Open eclipse-> New-> C/C ++-> makefile project-> Hello World C ++ Project
Click "finish"
Type the program code
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream. h>
# Include <string>
Usingnamespace STD;
Int main (){
Puts ("Hello world !!! ");
While (1 ){
Printf ("enter the password:" N ");
Gets (CC );
If (strcmp (CC, "123456 ")! = 0 ){
Printf ("Password error, press any key to continue ");
} Else {
Printf ("Password :");
Printf ("% s", CC );
Break;
}
}
Return exit_success;
}
Archive. the archive is automatically compiled.
Click "Debug as"-> Local C/C ++ Application
The execution result is displayed on the console !!