Skip to main content

Rape Eclipse projects to behave like Visual Studio projects

This blog entry might get you up and running with Eclipse if you come from Visual Studio without you having the need to immediately look at how to create makefiles or how the eclipse workspace philosophy works. I expect that you are somewhat familiar with Visual C++ though.

I like Eclipse. Well.... no, i don't. I like Visual Studio especially for C#, but Visual C++ has some drawbacks, especially when used to code cross platform non-.NET and without precompiled headers.

Still I don't know why so many people find Eclipse so great, but granted, it has a very decent code completion, nice automake and a very good syntax highlighting. I use it too. Its the next best thing ive tried so far to VS.
What I hate about it are the project- and workspace philosophies of Eclipse and that the program is somewhat slow.

Visual Studio projects/solutions are much easier to use and you grasp its concepts quicker and, most importantly, you are free to include any file you want into your project independent where it lies. Under Eclipse you may only include files into your project that are beneath the structure of your workspace or even project directory.... stupid.
But there are workarounds for that, but they are well hidden and they took me a long time to find them, but if you stick to this guide you can use Eclipse CDT projects like you are used to from Visual Studio.
This is especially vital if you want to work on a structure that was created for use with visual studio but you are now switching to eclipse! The great thing about the here described workaround will be that you will still be able to use autocomplete and syntax highlighting as well as automake!


This was tested with Eclipse 3.3 under Ubuntu with CDT 4.0 installed:

I take you have already a workspace created and eclipse started.
First, create a CDT project by File -> New -> C++ Project. Click finnish.
Use a name you like and choose a location you like
In your project workspace you will now see a Project with the given name.

Consider everything you see in the Workspace View like your solution you see in the solution explorer in Visual Studio. So lets say a workspace is somewhat the equivalent to a solution. The project (you just created ) is somewhat equivalent to the projects of visual studio. i wont explain the differences, but there is an excellent article on this by IBM called "An introduction to Eclipse for Visual Studio users". Just google for it.


Here now some common places of Visual Studio and Eclipse that you might need often but do not know where to find if you are just used to either ONE of those apps:
If you right click your project and enter the properties you are in a window that is equivalent to the "project properties" of visual studio (if you right click your project in visual studio solution explorer and choose "properties") as well as to some things found in Visual Studio under
Tools -> Options -> Projects and Solutions.

The Point "VC++ directories" in visual studio that is found under "Projects and Solutions" can be set up in eclipse by:
right click your project and enter the properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Directories under Preprocessor,
you can set preprocessor statements there like you are used in visual studio under
Tools -> Options -> Projects and Solutions -> C/C++ -> Preprocessor.

The additional libraries to be linked, found in Visual Studio under
Tools -> Options -> Projects and Solutions -> Librarian -> Additional Dependencies are under eclipse under
right click your project and enter the properties -> C/C++ Build -> Settings -> GCC C++ Linker -> Directories

By the way the equivalent of the .sln and the .proj files of visual studio are the .project and .cproject files under Eclipse CDT.

so far so good. by the decriptions above you should be able to include all the libraries and header files into your to-be eclipse project how you need them.
so lets get to include some files.

now, under VS we are used to just drag some C++ files from some place on the file system via explorer into our project and they are compiled with the rest of our files (if visual studio is able to find the include files that is. see above how to set up the paths to discover the include files).

under eclipse you cannot do that the files would need to lie beneath your defined workspace path (like already said). but you can work around that and add files from somewhere on your file system into your project anyway, but this is hidden and can be found at a very unlogic place in my opinion:
right click on your project -> New -> File -> Advanced -> check "Link to file in the file system -> Browse -> choose the file you'd like to use.
The file is now included into your project!

Provided Eclipse can resolve the include paths of your cpp file, your project now builds!

bytes

Comments