Build an eclipse C/C ++ Development Environment

Source: Internet
Author: User
Tags gdb debugger

Build an eclipse C/C ++ development environment:
1. Download and install eclipse for C ++: http://www.eclipse.org. The latest version is based on Eclipse 3.5 galileowith the file name eclipse-cpp-galileo-sr1-win32.zip. Set the working directory to D:/workspace_cpp.
2. eclipse for C/C ++ ide does not have a C/C ++ compiler or debugger. In Windows, you can use mingw or cygwin. Mingw and cygwin are two main methods to obtain the GNU toolchain. The biggest difference between the two is that mingw uses the Windows C Runtime Library, called mscvrt, while cygwin uses a set of GPL-based DLLs (GPL protocol is contagious, after you use the software under the GPL protocol, you must also follow the GPL Protocol). Therefore, mingw avoids the GPL protocol. Mingw is generally recommended because mingw and CDT can be well integrated. Before that, mingw-5.1.6.exe is used.
Solution 1: In the compiler base tool, C ++, Object C, Fortran, Java, and other compilers (do not install make, because msys can be installed later, which is a better implementation solution, including make and many other useful GNU tools); I installed all except make, and there was actually a Ada compiler. The supervisor installation process is very slow. For mingw-5.1.6.exe, many files need to be downloaded, and GCC 3.4.5 is installed, which is an old version. Gdb debugger is not installed when the MinGW-5.1.6 is installed. Decompress the package and copy all the files in various directories (bin and share) to the corresponding directory of the mingw installation directory (set to D:/mingw. To be able to use makefile, install the msys integrated with GNU make. Download msys-1.0.11.exe and install msys-1.0.11.exe. Set the installation directory to D:/msys/1.0. At the end of the installation, a command interface is displayed. "Y" is used for both issues, and then the mingw installation path is notified. The installation is complete. Then, add the paths d:/mingw/bin and D:/msys/1.0/bin to the path of the system environment variable. At this time, eclipse can compile and execute C/C ++ projects, but I found that GDB cannot be used for debugging and errors are always made when GDB is called. I guess it may be the dependency between software. Because GDB 7.0.1 is the latest version, many software versions installed in mingw 5.1.6 are earlier.
Solution 2: We recommend that you find an integrated and compiled mingw on the Internet for installation. I recommend using TDM/mingw, address: http://www.tdragon.net/recentgcc/, which includes the c/c?#compiler Compiler: gdb=gnu make (these three are required to build a complete eclipse C/C ++ Development Environment). The latest version of GCC 4.4.1 is used here, the support for C ++ 0x is complete. You can also download compilers in other languages during installation. After installation, change mingw32-make.exeunder bind to make.exe and add path D:/mingw/bin to the environment variable path (otherwise, you can compile and execute the project, however, when debugging the project, you will be prompted that you cannot execute GDB -- version. We can see that GDB cannot be found ). The installation is complete. When using this solution, I found that there was no problem, and debugging was also possible, and it was the latest version of GCC!
Solution 3: mingw-nuwen, which is another compiled mingw, uses the latest version of GCC 4.4.1 at http://nuwen.net/mingw.html. However, it does not integrate GDB (it should be installed as in solution 1 ). However, it integrates the compiled boost library.
3. Create a simple helloworld C ++ project named helloworld. This is very simple. Just create a template by pressing the wizard. Click Run (or right-click the corresponding shortcut menu. If you cannot run the program, you can choose run configurations to create a run configuration, specify the project and the name of the program to run, and run it.
4. Create a makefile project. Select New C ++ project-> makefile project-> Empty Project. We create an empty project and there is nothing in it after the project is created (except for two. project files ). Create a source file main. cpp and a make file makefile to the root directory.
Main. CPP Code:

/* <Br/> * Main. CPP <br/> */<br/> # include <iostream> <br/> using namespace STD; <br/> int main () {<br/> // say hello five times <br/> for (INT Index = 0; index <5; ++ index) <br/> cout <"helloworld! "<Endl; <br/> char input = 'I'; <br/> cout <" to exit, press 'M' "<Endl; <br/> while (input! = 'M') {<br/> CIN> input; <br/> cout <"you just entered" <input <br/> <"you need to enter m to exit. "<Endl; <br/>}< br/> exit (0); <br/>}

Makefile code:

ALL: hello.exe <br/> clean: <br/> rm main. O hello.exe <br/> hello.exe: Main. O <br/> G ++-g-o Hello main. O <br/> main. o: <br/> G ++-C-G main. CPP

Note that tab rather than space is used to indent the first line of each target command in makefile. If no separator... is prompted during compilation, there is a problem here.
Select a project and click build (or click the hammer) to build the generated program. To run hello.exe, right-click the project, select Run configurations, create a run configuration, and set the program name hello.exe to run.
Debug project: Right-click the project and select debug configurations (or select under the run menu) to generate a run configuration. Specify Debugger in the debug tab and use GDB/MI, click debug to perform debugging.

Related Article

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.