Migrate Visual Studio C and C++ projects to Eclipse CDT

A step-by-step guide to moving Microsoft VS projects to Eclipse C/C++ Development Toolkit

The Eclipse Platform is an open source tool to assist you with moving a project from the design to the test phase within a single development environment and without the need for separate tools for each stage. Eclipse was developed to assist the tools development community, concentrating on the core functionality of the tool instead of concentrating on the IDE itself. This is achievable because of programming model of Eclipse, which supports software building blocks called plug-ins.

Originally, Eclipse started with Java programming IDE, as it was the need of the hour. Because of its extensibility, it was embraced for developing applications for other programming languages, such as COBOL and C/C++.

The focus of this article is on C and C++ applications. Most C and C++ projects for deployment on Windows are developed using Microsoft Visual Studio. This article provides a step-by-step procedure for migrating Microsoft Visual Studio C/C++ (MSVC) projects to Eclipse. Along the way, we compare and contrast the benefits of using MSVC and Eclipse CDT.

Prerequisites

Eclipse Platform Download Eclipse from the Eclipse Foundation.

Eclipse C++ Development Toolkit (CDT) Get this Eclipse plug-in for C and C++ development (see About CDT).

Visual Studio/Platform SDK This should be your current development IDE for C/C++ applications in Windows. The recent version of Platform SDK (MSVC Express) is undergoing some changes that restricts you to building executables in the conventional way using an nmake makefile. This article assumes you are building the executable through a makefile. Be sure to identify the version you are using.

See Related topics for links to download each.

Visual Studio and Eclipse compared

Microsoft Visual Studio has a long history with wide use among Windows application developers. It is the leader in C and C++ Microsoft Windows application development, as well. By contrast, Eclipse CDT is relatively new and quite popular these days in the developers community. Eclipse CDT is designed to satisfy the developers of many OS platforms, such as Linux®, and is dependent on the gcc compiler and other open source tools.

There are many ways of comparing Eclipse with Visual Studio. One can compare the user interface (UI), architecture, cost, manageability, and many other criteria. Since this article looks at C and C++ development, we compare and contrast the strengths of both the tools with respect to C and C++ application development for Windows.

C/C++ development compared on Windows

Microsoft Visual Studio C/C++ Eclipse CDT Nature of license Proprietary Open source Programming languages supported Specific to C/C++ and Microsoft-supported programming languages Parallel different programming languages (COBOL, the Java programming language, and others), along with C/C++ SDLC phases supported Only coding Designing, coding, configuration management, testing, etc. Debugging Complete debugging support No debugging support; debugging support available only for gcc-compiled C code on platforms other than Windows. Microsoft Debugging Tools for Windows required Resource editor Comprehensive resource editor No resource editor Testing No testing tools as part of Visual Studio; third-party tools must be used CppUnit can be used (see Related topics for more information) MFC programming Development support for MFC application (wizard, code templates, etc.) No support Plug-in tools development Visual Studio 6 does not support any plugable software components Based on a plug-in architecture Tools specific to Microsoft Windows Spy++, error look-up, ActiveX Container, and others No tools specific for Windows platforms

About CDT

Eclipse C++ Development Toolkit (CDT) is an extension to the Eclipse platform in the form of a plug-in. This plug-in is available for download for all platforms. The open source nature of the plug-in with its user-friendliness makes it more popular not just among the Linux developers but also among C++ developers on other platforms. CDT and the Web Tools plug-ins are the two most popular Eclipse plug-ins. Nearly two out of three developers using CDT are Windows users.

CDT has subcomponents or plug-ins that are independent projects in the CDT community. The most important is the CDT primary plug-in, which provides the core CDT capabilities. CDT Debug UI provides the UI capabilities for the debug editors and views. CDT UI plug-in provides the UI-related features, views, editors, wizards, etc. CDT Debug provides core debugging capabilities. CDT Feature provides CDT Feature component. CDT core presents Core Model, CDOM, and other core components. CDT Launch provides launch mechanism for launching external executables and tools. CDT Debug MI is the application connector for MI-compatible debuggers.

CDT editors have several features that make them popular. For example, syntax highlighting and code assist make software development quick and easy. Syntax highlighting is configurable and can be personalized to your individual taste. Code assist is the code completion feature that is similar to the one in Visual Studio. Custom-defined code templates can be added to the plug-in, which can be used by code assist.

In the following sections, we will learn how to use CDT effectively to migrate the Visual Studio projects to the Eclipse CDT Workbench.

VS to Eclipse

In this section, we migrate a simple HelloWorld Win32 application developed using Microsoft Visual C++ 6.

If you do not have an existing Win32 application, create a HelloWorld Win32 application using Visual Studio. Create a makefile from the Projects > Export Makefile menu in Visual Studio. Figure 1. Create a HelloWorld Win32 application using Visual Studio

Start Eclipse and open the C/C++ perspective. Select Window > Open Perspective > Other Figure 2a. Open the C/C++ perspective Select C/C++ perspective Figure 2b. Select C/C++ perspective

Note: C/C++ perspective will be listed in the Select Perspective dialog only if the CDT plug-in is installed.

Create a standard C/C++ Make project via File > New > Standard Make C++ Project. Name the project HelloEclipse in the Project Name edit box in the New Project dialog that appears and click Finish. Figure 3a. It's HelloWorld time Figure 3b. Name your project HelloEclipse

Now we have to import the files created by Visual Studio into Eclipse. Go to File > Import. Select Filesystem in the Import dialog and click Next. If the newly created project is not visible, go to Window > ShowView > C/C++ project. Figure 4. Import the HelloWorld Visual Studio project files

Browse to the directory where the Visual Studio project was created, select the *.c*, *.h*,*.rc,*.ico and the .mak file to be imported and click Finish. Figure 5. Import the *.c*, *.h*,*.rc,*.ico and .mak files

Addition of environment variables Figure 6. Add environment variables

Right-click on the project and select Properties. In the Properties for HelloEclipse dialog, select C/C++ Make Project on the left side, and add INCLUDE and LIB environment variables to point to Visual Studio's include and lib paths. If you are using the platform SDK, point to its include and lib directories. Figure 7. Point the Visual Studio include and lib paths in the right direction

Open the .mak file imported from the Visual Studio project and make the following changes: Change the configuration (CFG) from Debug to Release so we get a release version of the application. It would look like CFG=HelloWin - Win32 Release . Figure 8a. Change the configuration from Debug to Release Add the command for executing the application in the ALL: tag: @cmd /c $(OUTDIR)\$(EXENAME).exe Define EXENAME=HelloWin Figure 8b. Define EXENAME

The next step is to create a new make target. Right-click on our current project and click on Create Make Target. Figure 9a. Create a new make target Create a make target for our project. "Target name" specifies any name you wish. "Make target" specifies the .mak file we just modified in the previous step. "Build command" is specified by unchecking the Use default checkbox in the build command so the build command is nmake . To make the Make targets view visible, go to Window > Show View > Make Targets. Figure 9b. The make target should be HelloWin.mak

Double-click on the HelloEclipse target we created to build and run the Win32 application. Figure 10. Run the application

With VC++ 2005 Express, making many changes in the traditional Visual Studio C/C++, there is a project initiated at Eclipse to solve this issue. Visit Eclipse MSVC for details (see Related topics).

Challenges to Eclipse CDT as an IDE for Windows development

Let's look at the various challenges posed by Eclipse CDT in various phases of the software development cycle.

Design

UML has become the de-facto standard for representing and designing software applications using object-oriented languages. IBM offers two Eclipse-based Java development tools: Rational® Application Developer and Rational Rose® XDE Developer for Java technology. Both offer model-driven development with UML support, Java code round-trip engineering, automatic or on-demand model-code synchronization, and other helpful features. Though we have a UML plug-in for Eclipse, there is no tight integration between UML to C/C++ in Eclipse platform today.

Development

Visual Studio's most interesting feature is its resource editor. Whether it's the SDK or MFC resource editor, both are used extensively to develop the static UI controls for the application. Today, Eclipse CDT offers no support to develop a UI. Consider using the Eclipse visual editor project when generating .rc files for Windows development.

Microsoft changes its compilers between versions, which makes it a challenge for Eclipse CDT to support the various versions of SDK tools Microsoft releases.

It is not viable today for you to migrate MSVC code totally to open source. In Linux, such an undertaking is complex. The SDK tools of Microsoft cannot run on open source, such as Linux. The SDK tools have to be run within the Windows emulator to make the SDK tools run on Linux.

However currently in Windows platform, developers with the help of platform SDK, Eclipse CDT and Debugging Tools for Windows can see Eclipse platform as an alternative for MS Visual Studio.

Debugging

Eclipse CDT relies on GNU Debugger, GDB. GDB is a source-level debugger for C, C++, Ada, and other languages. Neither Eclipse nor GDB understand the debugging information generated by Microsoft compilers. As a result, it is a challenge to select CDT as a full-time development environment for Windows development. However, you can use Debugging Tools for Windows for debugging side by side with Eclipse as a development environment.

Testing

CppUnit is the testing framework for C/C++ similar to JUnit for Java. The CppUnit plug-in for Eclipse is also available and can be used side by side with CDT for testing the CPP code. See Related topics for a CppUnit tutorial.

Tools and other criteria

Apart from normal SDK development on Windows, Visual Studio supports many other developments, including DDK, .NET, WMI, Web development, IE component development, MDAC, and more. More contributions are expected in this space from Eclipse plug-in development community.

All open source tools, such as listdlls, process explorer, and task handler, can be considered to provide support inside Eclipse CDT, which can bridge this gap to a certain extent.

Conclusion

The growing popularity, versatility, and open source nature of Eclipse motivates many to embrace Eclipse as the development platform of the future. Nevertheless, porting Windows applications to use open source development tools like GCC, GDB, or GCC/GDB for Windows providing functionalities similar to Windows SDK is a nontrivial task today.

However, Eclipse is an effective open source alternative to visual studio when we consider the entire SDLC phases. With more and more plug-ins supported in Eclipse for C/C++ application development in Windows, Eclipse CDT may become a default IDE for C/C++ development for Windows.

Downloadable resources

Related topics