Build a C/C ++ development environment using eclipse in Windows

Source: Internet
Author: User
Tags gdb debugger

This article assumes that you are familiar with the installation of Java and eclipse, and can start and run eclipse smoothly. in addition, software versions are constantly updated and may be inaccurate in some places. The latest and original documents shall prevail.

It has been 5 or 6 years since the last C ++ program was written and tuned. It has been a tough time and many things have to be picked up again. There are many C/C ++ ides in windows, and I know MS Visual Studio and Borland C ++, but these are copyrighted. I don't need to pay for it, but because I am too familiar with Eclipse, I chose eclipse + GNU toolchain (the word toolchain is very good ).

1. First download eclipse for C ++. The latest version is based on Eclipse 3.5.1 and is called Galileo (Galileo). I can't stand this strange name. Why isn't it Bruno? The previous version 3.4 seems to be called Ganymede (Wei San ). : Http://eclipse.org/downloads/, select 32bit for windows, the file name is called eclipse-cpp-galileo-SR1-win32.zip

2. decompress the package and run it directly. Note: At least JDK has been installed (I use JDK 1.6 ). After running, a gray-blue welcome page appears, entering tutorials. Reading tutorial is a good habit.

3. first understand what CDT is, C/C ++ development toolkit, bulabula... then it said that this item does not contain the C/C ++ compiler and debugger. You have to do it yourself.

4. Continue. In Windows, mingw and cygwin are two main methods for obtaining the GNU toolchain (GNU toolchain, a series of tool kits under GNU, my understanding is mainly the GCC tool series ). 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.

5. mingw and CDT can be well integrated. Okay, let's install mingw (mingw is the meaning of minimal GNU for Windows, this download process is quite slow, and I spent more than half an hour ). When the cursor was mingw-5.1.6.exe, I came up with a full install. Do not install the mingw make feature as the msys version of make from Step 5 is a more complete implementation of make. (do not install make of mingw,
Msys in step 1 is a better implementation solution)

6. In order to avoid possible problems in the future, the reinstallation is uninstalled. Here is the complete installation steps:
Download mingw, address http://sourceforge.net/projects/mingw/files/
2) install mingw base tool and G ++ Compiler (do not install make). I have installed all the files except make, and there is actually a Ada compiler in it.
 

3) The current version (it refers to the MinGW-5.1.3, but I do not have 5.1.6) does not install gdb debugger, download it: http://downloads.sourceforge.net/mingw/gdb-6.6.tar.bz2
4)decompress gdb-6.6.tar.bz2 to the place where you install mingw, gdb-6.6/also has a series of bin, inclue folder, copy directly to mingw to overwrite it
5) If you want to use makefile, download the MSYS-1.0.10.exe, msys is an implementation of make and command line. Well, use it. Http://downloads.sourceforge.net/mingw/MSYS-1.0.10.exe
The installation interface is a command interface. Write 2 "Y" and inform mingw of the installation path.
 

OK. The installation is complete. Below are two small examples.

7. First, create a simple helloworld C ++ project. This is very simple. Just create a template by following the wizard.
 

Select Run configurations when running, and double-click C/C ++ application to create a new run configuration.

8. Create a makefile project. Select New C ++ project-> makefile project-> Empty Project. We will create an empty project with nothing in it after the project is created (except for two. project file). At this time, we need to create a source file and a make file: Main. CPP and makefile are created in the root directory as follows:
 

C ++ code
  1. /*
  2. * Main. cpp
  3. */
  4. # Include <iostream>
  5. Using namespace STD;
  6. Int main (){
  7. // Say hello five times
  8. For (INT Index = 0; index <5; ++ index)
  9. Cout <"helloworld! "<Endl;
  10. Char input = 'I ';
  11. Cout <"to exit, press 'M'" <Endl;
  12. While (input! = 'M '){
  13. Cin> input;
  14. Cout <"you just entered" <Input
  15. <"You need to enter m to exit." <Endl;
  16. }
  17. Exit (0 );
  18. }

Makefile code

  1. ALL: hello.exe
  2. Clean:
  3. Rm main. O hello.exe
  4. Hello.exe: Main. o
  5. G ++-g-o Hello main. o
  6. Main. O:
  7. G ++-C-G main. cpp

Note that the first line indent in makefile uses tab rather than space. If no separator... is prompted during compilation, there is a problem here.

9. OK. Select the project and click build (or click the hammer). You will find this error: (cannot run program "make": Launching failedfailed, and our make.exe has not been set yet. Select the project, and directly alt-enter to the project properties page to add the msys bin to the path.
 

10. re-build.

Source Address http://metaphy.iteye.com/blog/560534? Page = 2 # comments

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.