Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1755638
  • 博文数量: 413
  • 博客积分: 8399
  • 博客等级: 中将
  • 技术积分: 4325
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-09 10:44
文章分类

全部博文(413)

文章存档

2015年(1)

2014年(18)

2013年(39)

2012年(163)

2011年(192)

分类: LINUX

2012-02-13 00:56:51

Cross-Platform C/C++ Development with Eclipse CDT
Cross Compile Linux to Windows

Another option for building Windows executables with Eclipse on Linux is to use a cross compiler. To use this option, CDT must have the cross compile extension enabled, and a cross compiler must be installed. Under Ubuntu 10.10, installing the mingw32 package will bring in everything required to build the sample project with the MinGW cross compiler. Next, we'll install CDT cross compile support.

To install CDT cross compile support, navigate to Help → Install New Software... In the Work With textbox, type cdt to filter down to CDT settings and select the CDT option. Expand CDT Optional Features and check the C/C++ Cross Compiler Support option. Hit Next and follow the instructions to complete the installation (Figure 8).

Figure 8: Setting up Windows cross-compilation on Linux.

Installing the CDT cross compiler support provides new build configuration options. To see the new options, follow the previous instructions for creating a new build configuration. Under the Import Predefined dropdown box, two new options are available: Executable→Cross GCC→Debug, and Executable→Cross GCC→Release. Create a new build configuration called Debug-Win and select the Cross GCC→Debug option.

When this configuration is selected, you'll notice a new option in the project settings called Cross Settings. Open the project settings, select Cross Settings, and enter i586-mingw32msvc- into the prefix textbox. If the prefix box is left empty, the IDE will use the default system tools for linking and compiling (Figure 9).

Figure 9: The Cross Settings dialog box in Linux.

A Few Good Options

Eclipse offers a few options for creating cross-platform projects. It takes a bit of futzing, but developing between Linux and Windows works seamlessly once the project is setup. And there are other options that we didn't cover such as using GCC on Linux and Windows or creating makefiles by hand. Each option has its own set of quirks for dealing with include directories, maintainability, third-party libraries, and debugging.

In this article, we covered handling include directories and the options covered are arguably the easiest to maintain (since Eclipse automatically handles the makefile). If you want to debug on both platforms or use third-party libraries, there's a bit more work to do depending on the option chosen for cross-platform development. But we'll leave that for another time.

Ben DuPont is a software engineer. After 10 years of developing software and systems in a corporate environment, he founded Nebland Software, an independent software consulting company.


阅读(3470) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~