Eclipse Windows Toolchain Setup
Before Eclipse can use the Visual Studio compiler and take advantage of code completion, a little setup is required. Indigo comes with a toolchain pointed at the Visual Studio tools, but it doesn't have the
include directory configured in the IDE, and the Visual Studio tools aren't in the path variable by default.
Fixing the last problem is easy: Visual Studio comes with a batch file (
Visual Studio Command Prompt (2010)) that sets the appropriate environment variables for running Visual Studio. Running the batch file updates the path variable and adds few other variables that we'll be using to configure Eclipse. For my testing, I first ran the batch file (Start→Microsoft Visual Studio Expresss 2010→Visual Studio Command Prompt (2010)), and then changed to the Eclipse directory and launched Eclipse from the command line.
Next, it's time to create a project and deal with the missing
include directory problem.
Start Eclipse from the VS command prompt and select File→New→C++ Project. Name the project
sort_win. Select "Empty Project" and, under toolchains, select Microsoft Visual C++. Click finish.
Next, add a source file called main.cpp and paste in the code mentioned above. At this point, the program should compile and link without error. But the IDE does not have the path to the
include files, causing it to complain and mark every line as an error. Let me stress that the program still compiles.
In addition to claiming numerous errors and complaining about missing
include files, code completion does not work. To fix this issue (and get rid of the errors), we need to point the IDE to the
include directory. This is where a Visual Studio project comes in handy.
To figure out what paths Visual Studio uses, I created a C++ project. After a little browsing, I found the default
include directories: right-click on the project, select Properties, then expand Configuration Properties and select VC++ Directories (Figure 4).
The directory we're interested in is Include Directories. Editing this value brings up a list of four configured directories: two of them are for Windows SDKs that we don't need, and another is for
atlmfc stuff, which is also not needed. The only useful directory to us is
Earlier, I mentioned that running the VS batch file would setup variables that will be useful.
VCInstallDir is one of those variables. Now, we just need to add this
include path to the Eclipse project.
In Visual Studio, using an environment variable is done by surrounding the variable with parentheses. In Eclipse, you must use curly brackets. The path to add to Eclipse is
There are two locations where the path can be added. In Eclipse, right-click on the project and select Properties. Expand C/C++ General and select Paths and Symbols. Select either C source file or C++ source file on the Include tab. Click the Add button and place the
include path in the directory textbox.
After adding the directory, you might still have a bunch of the code completion that the database didn't rebuild. To rebuild the database, right-click on the project, select Index→Rebuild, and the errors will disappear.