Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Tips for Making Copying of Eclipse CDT Projects Easier

DZone's Guide to

Tips for Making Copying of Eclipse CDT Projects Easier

Eclipse CDT projects can be great starting points, but if you want to copy one over to your environment, there are a few pitfalls to be aware of.

· IoT Zone
Free Resource

Instead of creating a new project from scratch, often it is simpler to copy an existing Eclipse CDT project, then change it and work from there. To copy-paste a project in Eclipse:

  1. Select the project in the Project Explorer View (CTRL-C on Windows)
    Copy of a project
  2. Then paste it in the Project Explorer View (CTRL-V on Windows), and I can specify the new name:
    Paste of Project

However, to make that process simpler, a few things have to be done right in the ‘source’ project first.

I’m using the ‘copy-paste’ project in my classes too, where students get a ‘master’ project they can use as a base — multiple times during the labs if necessary.

Eclipse copies all the files in the project folders. Linked files and folders (see Link to Files and Folders in Eclipse) in the project are still linked files and folders. So they will be shared between the original project and the copy one.

Usually, I avoid linked files and folders, as they easily can be a source of problems. If using links, then make them project-relative, but this means that the copied project needs to match this, or the linked location needs to be updated.

Linked Folder Location


To make projects easy to copy, avoid any linked files or folders: have the source project ‘standalone’, means have the necessary files be physically present in the source project, and not outside.

Artifact Name

With the copied project getting a new name, make sure that the build output (artifact name) is not a hardcoded one. Use

${ProjectName}


Instead:

Artifact Name

That way, the output file for the new project is matching the new project name.

The compiler/assembler/linker needs some path and file information. Do *not* use absolute paths like “C:\myProjects\…”. Instead, use the the Eclipse CDT project variable ${ProjDirPath} and have paths surrounded by double quotes (if your project is named ‘Copy of MyProject’ or similar).

Even better, use a relative path like

"../Sources"


As shown below:

Project Path Settings

The ‘current directory’ of the build tools (at least for the GNU ARM Eclipse integration) is the build directory location:

Build Directory Location

Using “../Sources” not only makes things relative to the project, it shortens the command line length which avoids a common length problem (see Solving the 8192 Character Command Line Limit on Windows).

Oh, and if you have not noticed: I’m using the ‘Linux’ forward slashes in the paths:

"../Sources"


instead of “..\Sources”, that way I keep things compatible between Windows and Linux/Mac :-).

Clean

As with the copy we got all the build things from the earlier project, it is a good idea to make a Project > Clean to get rid of that old stuff:

clean of project

Now build the project, and it should (hopefully) build just fine.

Now, this is the most complicated part.

To make sure the debug configurations get copied too, make sure they are stored as files in the projects (see Sharing Debug Configuration with Eclipse):

Shared Debug Configuartion

Now they get copied, but having the old names (remember: Eclipse just does the copying, it has no clue about the content):

Copied Launch Configurations

So one obvious step would be to rename the files matching the new project name. It is optional because Eclipse CDT only cares about the .launch file extension to recognize something as a debug launch configuration. However, if the ‘old’ and ‘copied’ project are still present in the workspace, renaming avoids confusion.

The new configurations show up, but they have the wrong project name and application file listed:

Launch Configurations

An easy way is to change them in the above dialog. Another way is to use a text editor or script file to change the following string attribute keys in the launch file:

<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="application.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="ProjectName"/>


project and application name in launch file

Summary

With following a few basic things, a copy of an existing Eclipse CDT project is not that hard. Make sure you are not using linked files and folders, that the build artifact and path names are not hard-coded, and things should be much easier. While I have used the NXP Kinetis Design Studio in above screenshots, things are very similar to other Eclipse distributions, too.

Topics:
eclipse ide ,iot app development ,iot ,tutorial

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}