C++ Resources

Updated on January 7 2017



C++RESOURCES C++EclipseOnLinux

Deborah R. Fowler



Eclipse on Linux for C++

Updated on  Jan 17  2013
Updated on Feb 19  2015

At school you will likely be asked to use Linux for our programming classes. (Unless you are majoring in games). Since I use Windows at home, documentation is provided for both on this site.



Getting Started (instruction for a IDE managed project):

(Note - I have been testing on Windows, this will be tested before start of quarter).

1. Start up eclipse
2. Select File / New / Project
This brings up a dialog box.
3. Now expand the C/C++ Project folder
and click on C++ Project then hit next (or just double click)
At this point it will open to GNU Autotools/ Empty Project on the left and Toolchains GNU Autotools Toolchain on the right. This is NOT what you want.
4. Expand the folder labeled Executable (the little arrow to the left of it - clicking won't work)
and select either Empty Project or Hello World C++ Project (a good starting point). Once you have selected the Project type on the left a list of Toolchains appears on the right. Click GCC C++ Compiler or it may say Linux GCC
You will need to give a name in the Project name field at the top. Now Select Finish.

You should now see a display with the list of projects on the left, a code editing window in the middle and an error or "Problems" screen at the bottom.

Click on the   Hammer Icon  Hammer icon to build and the   Arrow Icon   right pointing green arrow to run.

(If you are not seeing the icons, go to the "eclipse page" and select workspace).


Tips:

If you make a change to your code and hit build, it will not acknowledge this change until you save the cpp file. This behavior is different from Visual Studios. However if you hit run it will tell you that the cpp file is changed and force a build at that point.

You can also create a project that allows you to control the makefile. These steps are included in the documentation if you look under Help/ C++ Development User Guide.

1. Follow Steps 1-3 as above. Now expand the folder labeled Makefile project and select empty project. Make sure it creates the include folder pointing to mingw. It appears that this method is not the most robust. The "Hello World" version is a good template to start with.



Changing workspaces

Start Eclipse and when prompted choose a workspace (if it doesn't exist it will be created - you must change this at Monty or it will not point to a directory you can write to).
If not prompted o to File->Switch workspace-> Other
Import your existing project with File->Import then General->Existing Projects into your workspace
Go to the folder with the project sources and select it, click finish


Adding OpenGL/Glut functionality to Eclipse on LINUX:

(I have tested this on linux but will review before start of quarter as my notes were a bit hard to read)
 
Under Project -> Properties
Expand C/C++ Build on the left of the dialog box
(Select Discovery Options
In the Tools section on the left, select GCC C++ Compiler)

Select Settings
In the Tool Settings one the left select  GCC C++ Linker / Libraries and on the right click the + icon to add libraries
GL
GLU
glut



Tips and troubleshooting:

Note that in your C++ code you must have the line for glutInit.

In addition, linux is pickier than Windows about capitalization. On Windows you can use GL or gl, on linux you must use GL
#include <GL/glut.h>

glutInit( &argc, argv );  
and since this is required, so are the arguments to main  int main( int argc, char *argv[] )

Also note: When using Windows and
#include <math.h>
M_PI exists when using c++ rather than Visual Studios so this line must be commented out of .h files or it will result in an error
// const double M_PI = 3.14159265;


You can also add this functionality for command line compiling (in a terminal window)
using g++ and flags -lGL -lGLU -lglut


Note if you want to find out more about g++ you can type g++ --help  (yes, there are two minus signs there)

NOTE: This differs on Windows. See documentation here.