Channels ▼
RSS

Design

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


Starting From Windows

At this point, we have a project in Eclipse under Windows that will build with Visual Studio compiler, there are no errors or warnings in the IDE, and code completion works. The next step is to get the source onto a Linux machine and configure a Linux build. I'm using SVN to transfer the project between machines but you can copy the project to your Linux system instead.

Once the source is on your Linux system, open the project in Eclipse. You will receive errors and warnings about missing include files and unresolved symbols, and the application won't build. The IDE is using Windows paths and build tools, which are obviously not valid under Linux. The first thing we need to do is create debug and release builds for Linux that point to the correct compiler.

right-click on the sort_win project and select Properties. Expand C/C++ Build and click on Settings. Select the Manage Configurations... button, and select the New... button, in the Manage Configurations window. Under name, enter Debug-Linux, select the Import predefined radio button, and select Executable→Linux GCC→Debug. Select OK. Repeat this process substituting Release for Debug to create a Release build (see Figure 5).

Figure 5: Configuring Eclipse for a project on Linux.

After creating the new build configurations, enable Debug-Linux: right-click on the project, browse to Build Configurations→Set Active→Debug-Linux. The IDE will now use GCC to build the application, but the code completion index is incorrect. When building applications across platforms, each platform needs its own index. The IDE has a setting to use the active configuration for creating the index.

To enable this feature, right-click on the project and select Properties. Expand C/C++ General and select Indexer. Check the Enable Project Specific Settings at the top of the window, and select the Use Active Build Configuration at the bottom of the window. Select OK. If the errors don't disappear right a way, rebuild the index as described previously (Figure 6).

Figure 6: Configuring the Indexer options in Linux.

Starting from Linux

Creating a project in Linux and transferring to Windows is a nearly identical process. Select File→New→C++ Project. Name the project sort_lin, select Empty Project under project type, and select Linux GCC under Toolchains (Figure 7). Select Finish.

Figure 7: The new project dialog in Linux.

Next, add a main.cpp source file with the same source that was used in the Windows program. Once the project is complete, transfer it to your windows machine, launch Eclipse from the Visual Studio command prompt and open the project. You should notice that we have the same problem that we experienced previously when transferring from Windows to Linux: The IDE shows a bunch of errors and the project won't build. We need to add debug and release build configurations for Windows. Follow the previous instructions for adding new build configurations under Linux, but use the Executable→Microsoft Visual C++ →[Debug | Release] option. Next, add the path ${VCInstallDir}\include to both of the new build configurations.

If you activate the windows configurations, the project will build, but the IDE will still show a bunch of errors and warnings. As we did in Linux, we need to enable project-specific indexer settings. Follow the previous instructions to enable the settings and rebuild the index if needed. Make sure to add the Visual Studio path as mentioned previously before enabling project-specific indexer settings. A few times, I misspelled the directory and it defaulted back to use a fixed-build configuration. Double-check your settings if the errors don't disappear after rebuilding the index.


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