Being able to create cross-platform applications is becoming more and more important for developers. Here you will see where some of the basic Visual Studio C++ options are under Linux and Eclipse.
I recently began work on an SDL application that I was determined would run under Linux. I'm quite proficient in Visual Studio, but was at a loss when it came to Linux IDE's. In the end I settled for Eclipse (I had used it already as under the guise of the Flex Builder). This tutorial shows where some of the basic settings for Eclipse and Visual Studio are to get Visual Studio C++ developers up and running with Eclipse quickly.
In Visual Studio you have solutions, and solutions contain projects. A solution is really just a *.sln file containing information on the location of the projects it hosts.
A workspace is the Eclipse equivalent to Visual Studios solution. A workspace is a folder that contains a .metadata folder. This .metadata folder contains the details of the projects contained in the workspace.
To create a new C++ project in Eclipse click File -> New -> C++ Project.
Select Empty Project and click Next.
Then click Finish.
The two things almost every C++ application requires are the location of your external libraries and their header files.
First right click on the Eclipse project and select properties.
Then under the C/C++ General option select Paths and Symbols. It is here that you can add additional paths for the location of header files and libraries.
The Visual Studio equivilants are C++ -> General -> Addtional Include Directories
Linker -> General -> Additional Library Directories
In order to compile our test application we need two libraries: SDL and Boost. Unlike Windows, quite a lot of development libraries can be obtained and installed under Linux through the various package management tools that come with almost all distributions. In this case we will download the SDL library via the Synaptic Package Manager, and also manually download a source distribution of Boost (Boost can also be downloaded via the package manager, but downloading it manually will give us a chance to add some include paths).
Under the Synaptic Package Manager (for Ubuntu based distributes) find the libsdl1.2-dev package (or whatever is the latest version). Mark it for installation and apply the changes. This will install SDL, making the header files available under the /usr/include/SDL directory, and the library available under the /usr/lib directory. If you look back to the Paths and Symbols screenshot you will see that /usr/include/ and /usr/lib are already included in your C++ program.
Next download Boost from here. Extract it where ever you like. Click on the Includes tab in the Paths and Symbols options and click Add. Click the File System button and browse to the location where you extracted Boost. You will want to tick the Apply to all configurations option so both the Release and Debug versions have the location of this new directory available to them.
We don't need to add any additional library paths, but the process is exactly the same – you just click the Library Paths tab instead.
While we don't need to add any additional library paths, we do need to reference some additional libraries, specifically SDL.
Go to the C\C++ Build option. Under the tools option select GCC C++ Linker->Libraries. In the Libraries (-l) box click the icon that looks like a page with a plus sign. Type in SDL and click OK.
You have now added a reference to the a library file called libSDL.a. Unlike Visual Studio, which needs the entire file name of any library, Linux assumes a library has a “lib” prefix and ends with “.a”, so when you specify a library file you only include the middle of the file name.
The Visual Studio equivilant is Linker -> Input -> Additional Dependencies
Click OK and let Eclipse rebuild the workspace (it's an empty project, so it shouldn't take long).
Under the Project Explorer you should have an includes item. Underneath that you should now see your Boost directory.
Extract the contents of the sample application (from this SDL tutorial series) into the project directory, and then click File->Refresh.
The files should now be visible under the Project Explorer.
Click on the hammer icon. This will compile the project. If you have installed SDL and added the path to the boost library it should compile fine. Now click the green arrow. This will execute the application. You will probably see a screen pop up and then disappear. This is because the working directory is not set correctly.
Click the arrow pointing down next to the green arrow and click Run Configurations...
Select the Arguments tab.
Untick Use Default, and set the working directory to ${workspace_loc:testproject/Debug}. Click Apply and then Run.
The Visual Studio equivilent is Debugging -> Working Directory
Congratulations, you have compiled and run a C++ application in Eclipse.
While there are hundreds of options available in Eclipse, downloading development libraries, setting include and library paths, adding new library references and setting up the debugging paths is enough to get most C++ applications compiled and running.
Download the sample application here.