How To Install and Use Eclipse CDT For C - C++ Programming PDF
How To Install and Use Eclipse CDT For C - C++ Programming PDF
HowtoinstallanduseEclipseCDTforC/C++programming
Eclipse 4.3
(Kepler) for
C/C++
Programming
How To Install
Eclipse CDT 8.2 and Get Started
Eclipse is an opensource Integrated Development Environment IDE supported by IBM. The
mother site is @ www.eclipse.org. Eclipse is popular for Java project development. It also
supports C/C++, PHP, Python, Perl, and other web project developments via extensible plugins.
Eclipse is crossplatform and runs under Windows, Linux and Mac OS.
1/10
12/30/2015
HowtoinstallanduseEclipseCDTforC/C++programming
1. If you have already installed "Eclipse for Java Developers" or other Eclipse packages, you
could install the CDT plugin as follows:
Launch Eclipse Help Install New Software In "Work with" field, pull down the drop
down menu and select "Kepler http://download.eclipse.org/releases/kepler" or juno for
Eclipse 4.2; or helios for Eclipse 3.7.
In "Name" box, expand "Programming Language" node Check "C/C++ Development
Tools" "Next" ... "Finish".
2. If you have not install any Eclipse package, you could download "Eclipse IDE for C/C++
Developers" from http://www.eclipse.org/downloads, and unzip the downloaded file into a
directory of your choice.
Step 2: Configuration
You do NOT need to do any configuration, as long as the Cygwin or MinGW binaries are included
in the PATH environment variable. CDT searches the PATH to discover the C/C++ compilers.
2/10
12/30/2015
HowtoinstallanduseEclipseCDTforC/C++programming
intmain(){
cout<<"Hello,world!"<<endl;
return0;
}
3/10
12/30/2015
HowtoinstallanduseEclipseCDTforC/C++programming
2. "Add" the following directories to "GNU C++", where $MINGW_HOME is your Cygwin installed
directory:
$MINGW_HOME\lib\gcc\mingw32\4.6.x\include\c++
$MINGW_HOME\lib\gcc\mingw32\4.6.x\include\c++\mingw32
$MINGW_HOME\lib\gcc\mingw32\4.6.x\include\c++\backward
$MINGW_HOME\lib\gcc\mingw32\4.6.x\include
$MINGW_HOME\include
$MINGW_HOME\lib\gcc\mingw32\4.6.x\includefixed
NOTE: To find the header paths, you can do a search on headers such as "stdio.h" for C and
"iostream" for C++ under the Cygwin or MinGW installed directory.
Note : If you encounter "error while loading shared libraries" during link. Install
"libmpfr4" in cygwin.
Step 3: Compile/Build
Rightclick on the "FirstProject" or use the "Project" menu choose "Build Project" to
compile and link the program.
Step 4: Run
To run the program, rightclick on the "FirstProject" or anywhere on the source "test.cpp",
or select the "Run" menu Run As Local C/C++ Application If ask, choose Cygwin's gdb
debugger The output "Hello, world!" appears on the "Console" panel.
NOTE: You need to create a new C++ project for EACH of your programming problems. This is
messy for writing toy programs!
2.2C Program
Follow the same steps as above. Create a "C Project" instead of "C++ Project". Try the following
Helloworld program called "Hello.c".
#include<stdio.h>
intmain(){
printf("Hello,world!\n");
return0;
}
4/10
12/30/2015
HowtoinstallanduseEclipseCDTforC/C++programming
From "File" menu New Project... C/C++ C++ project In "Project name", enter
"HelloCppMakefile" In "Project type", choose "Makefile Project ", "Empty Project" In
"Toolchains", choose "Cygwin GCC" or "MinGW GCC". Ignore the warning message.
intmain(){
cout<<"Hello,world!"<<endl;
return0;
}
clean:
rmHello.oHello.exe
Hello.exe:Hello.o
g++goHello.exeHello.o
Hello.o:Hello.cpp
g++cgHello.cpp
https://www3.ntu.edu.sg/home/ehchua/programming/howto/EclipseCpp_HowTo.html
5/10
12/30/2015
HowtoinstallanduseEclipseCDTforC/C++programming
Step 0: Write a C++ Program The following program computes and prints the factorial
of n =1*2*3*...*n. The program, however, has a logical error and produce a wrong answer for
n=20 "TheFactorialof20is2102132736" a negative number?!.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
usingnamespacestd;
intmain(){
intn=20;
intfactorial=1;
//n!=1*2*3...*n
for(inti=1;i<=n;i++){
factorial*=i;
}
cout<<"TheFactorialof"<<n<<"is"<<factorial<<endl;
return0;
}
TheFactorialof20is2102132736
Step 1: Set an Initial Breakpoint A breakpoint suspends program execution for you to
examine the internal states e.g., value of variables of the program. Before starting the debugger,
you need to set at least one breakpoint to suspend the execution inside the program. Set a
breakpoint at main() function by doubleclicking on the leftmargin of the line containing
main(). A blue circle appears in the leftmargin indicating a breakpoint is set at that line.
Step 2: Start Debugger Right click on the project or use the "Run" menu "Debug As"
"Local C/C++ Application" choose "Yes" to switch into "Debug" perspective A perspective is
https://www3.ntu.edu.sg/home/ehchua/programming/howto/EclipseCpp_HowTo.html
6/10
12/30/2015
HowtoinstallanduseEclipseCDTforC/C++programming
a particular arrangement of
panels to suits a certain
development task such as
editing or debugging. The
program begins execution
but suspends its operation at
the breakpoint, i.e., the
main() function.
As illustrated in the following
diagram, the highlighted line
also pointed to by a blue
arrow
indicates
the
statement to be executed in the next step.
thru
the
7/10
12/30/2015
HowtoinstallanduseEclipseCDTforC/C++programming
Step 5: Switching Back to C/C++ perspective Click the "C/C++" perspective icon
on the upperright corner to switch back to the "C/C++" perspective for further programming or
"Window" menu Open Perspective C/C++.
I can's stress more that mastering the use of debugger is crucial in programming. Explore the
features provided by the debuggers.
StepInto and StepReturn: To debug a function, you need to use "StepInto" to step into
the first statement of the method. You could use "StepReturn" to return back to the caller,
anywhere within the method. Alternatively, you could set a breakpoint inside a method.
NOTE: If you receive error message "Can't find a source file at /cygdrive/c..." during
debugging, you need to configure a mapping between "/cygdrive/c" and "c:/" assuming that
your program in kept in drive c. From "Window" "Preferences" "C/C++" "Debug"
"Common Source Lookup Path", select "Add" "Path Mapping".
8/10
12/30/2015
HowtoinstallanduseEclipseCDTforC/C++programming
3. OpenGL with GLUT: For Cygwin, you need to install gcc, g++, gdb, make under Devel
category and opengl, freeglut under graphics category. The headers gl.h, glu.h, glut.h
are kept in $cygwin\usr\include\w32api\GL. Use #include <GL/gl__.h> to include
the headers. The libraries libopengl32.a libglu32.a and libglut32.a are kept in
$cygwin\lib\w32api. To specify these libraries in linking, use lopengl32 lglu32
lglut32 options without the lib prefix and .a extension.
4. OpenGL with SDL: Download SDL from http://www.libsdl.org. Choose Development
Libraries win32 mingw32 Unzip. Copy the headers directory SDLunder include
to
copy
$cygwin\usr\include\w32api;
$cygwin\lib\w32api;
copy
the
all
runtime
the
library
library
SDL.dll
files
in
lib
into
under
bin
into
Comment
Directive:
pragma
comment
directive,
e.g.,
#pragma
site
http://gcc.gnu.org;
GCC
manual
9/10
12/30/2015
HowtoinstallanduseEclipseCDTforC/C++programming
Feedback, comments, corrections, and errata can be sent to Chua HockChuan ehchua@ntu.edu.sg |
HOME
https://www3.ntu.edu.sg/home/ehchua/programming/howto/EclipseCpp_HowTo.html
10/10