Channels ▼
RSS

Open Source

Cross-Platform C/C++ Development with Eclipse CDT


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).

Figure 4: The project in Eclipse under Windows.

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 $(VCInstallDir)\include.

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 ${VCInstallDir}\include.

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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video