CDT has a complete Templating mechanism for creating new projects.
Basically, you expand the extension point org.eclipse.cdt.core.templates and point to the template.xml file, which has a bunch of commands that you can do. You do not need to write Java code for this, but you need to create a plug-in project.
Types of things you can do:
- Create folders
- Add files to the project
- Set the parameters of the managed assembly (this is most relevant because you can set the compiler parameters and add libraries, etc.).
- Add additional pages to the Create Project Wizard to request additional information from the user.
There is a special section in the Eclipse documentation that tells how to do this: http://help.eclipse.org/mars/topic/org.eclipse.cdt.doc.isv/guide/projectTemplateEngine/index.html
The Hello World project that comes with the CDT has its own template here: https://github.com/eclipse/cdt/blob/master/build/org.eclipse.cdt.managedbuilder.gnu.ui/templates/projecttemplates/HelloWorldCAnsiProject/ template.xml
A small note: if you initially create your plug-in for installation as an unpacked plug-in, you can edit it, add new templates or edit the one you already made.
To go further, you can share this template plugin project with your team, and all of this will benefit from this feature.
Step by step
A step-by-step process for this (tested on Eclipse Mars.1 with installed CDT and Plug-in development tools plus an XML editor for editing template.xml)
- Create a plug
Plug-in project ( File | New | Other... | Plug-in project )

- Fill in the project name and click
Next / Finish until completion

You should now have files on your disk that look like this in the created project:
$ find . -type f ./.classpath ./bin/com/example/cdt/templates/Activator.class ./.project ./src/com/example/cdt/templates/Activator.java ./.settings/org.eclipse.jdt.core.prefs ./META-INF/MANIFEST.MF ./build.properties
- Open the plug-in.xml file and follow these steps.
- Select the
Extensions tab - Click Add
- Enter the extension point
org.eclipse.cdt.core.templates - Uncheck
Show only extension points [...] - Choose
org.eclipse.cdt.core.templates from the list - Click
Finish - Say
Yes about adding dependencies

- Add the necessary settings to
plugin.xml , as shown in the screenshot and the plugin.xml example in the code after.

<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> <extension point="org.eclipse.cdt.core.templates"> <template filterPattern=".*gcc" id="com.example.cdt.templates.template1" location="template/template.xml" projectType="org.eclipse.cdt.build.core.buildArtefactType.exe"> </template> </extension> </plugin>
- Now create
template.xml at the location specified in plugin.xml ( template/template.xml ), with this content:
<?xml version="1.0" encoding="ISO-8859-1"?> <template type="ProjTempl" version="1.0" supplier="Stack Overflow" revision="1.0" author="Jonah Graham" id="EXE" label="Qaru Example" description="An example for https://stackoverflow.com/questions/33092746/creating-a-new-c-project-in-eclipse-cdt-with-the-same-settings-as-another-proj." help="help.html"> <process type="org.eclipse.cdt.managedbuilder.core.NewManagedProject"> <simple name="name" value="$(projectName)" /> <simple name="artifactExtension" value="exe" /> <simple name="isCProject" value="true" /> </process> <process type="org.eclipse.cdt.core.CreateSourceFolder"> <simple name="projectName" value="$(projectName)" /> <simple name="path" value="src" /> </process> <process type="org.eclipse.cdt.core.AddFiles"> <simple name="projectName" value="$(projectName)" /> <complex-array name="files"> <element> <simple name="source" value="src/basename.c" /> <simple name="target" value="src/$(projectName).c" /> <simple name="replaceable" value="true" /> </element> </complex-array> </process> <process type="org.eclipse.cdt.ui.OpenFiles"> <simple name="projectName" value="$(projectName)" /> <complex-array name="files"> <element> <simple name="target" value="src/$(projectName).c" /> </element> </complex-array> </process> <process type="org.eclipse.cdt.managedbuilder.core.SetMBSBooleanOptionValue"> <simple name="projectName" value="$(projectName)" /> <complex-array name="resourcePaths"> <element> <simple name="id" value=".*compiler\.option\.warnings\.extrawarn.*" /> <simple name="value" value="true" /> <simple name="path" value="" /> </element> </complex-array> </process> <process type="org.eclipse.cdt.managedbuilder.core.SetMBSStringOptionValue"> <simple name="projectName" value="$(projectName)" /> <complex-array name="resourcePaths"> <element> <simple name="id" value=".*compiler\.option\.misc\.other.*" /> <simple name="value" value="-c -fmessage-length=0 -Werror" /> <simple name="path" value="" /> </element> </complex-array> </process> <process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringListOptionValues"> <simple name="projectName" value="$(projectName)" /> <complex-array name="resourcePaths"> <element> <simple name="id" value=".*link\.option\.libs.*" /> <simple-array name="values"> <element value="mylibname" /> </simple-array> <simple name="path" value="" /> </element> </complex-array> </process> </template>
- Add the source file specified in the template with any content you want in
template/src/basename.c
You should now have a directory structure that looks like this:
$ find . -type f ./.classpath ./template/src/basename.c ./template/template.xml ./bin/com/example/cdt/templates/Activator.class ./.project ./src/com/example/cdt/templates/Activator.java ./.settings/org.eclipse.jdt.core.prefs ./META-INF/MANIFEST.MF ./plugin.xml ./build.properties
Launch the Eclipse application for testing ( Run menu | Run As | Eclipse Application ). You can also right-click on a project and select Run As | Eclipse Application .
In a new Eclipse launch, run the project wizard and select the new project type C:

Starting the build shows the new settings (an error is expected, because in fact I do not have a library named mylibname):
Building file: ../src/hello2.c Invoking: GCC C Compiler gcc -O0 -g3 -Wall -Wextra -c -fmessage-length=0 -Werror -MMD -MP -MF"src/hello2.d" -MT"src/hello2.o" -o "src/hello2.o" "../src/hello2.c" Finished building: ../src/hello2.c Building target: hello2 Invoking: GCC C Linker gcc -o "hello2" ./src/hello2.o -lmylibname /usr/bin/ld: cannot find -lmylibname collect2: error: ld returned 1 exit status make: *** [hello2] Error 1
The hard part?
You may need to examine the .cproject file from the base project to determine the magic lines that go into the id fields. For example, in my .cproject for -Wextra I can see this:
<option id="gnu.c.compiler.option.warnings.extrawarn.176373860" name="Extra warnings (-Wextra)" superClass="gnu.c.compiler.option.warnings.extrawarn" value="true" valueType="boolean"/>
This translates this command into template.xml :
<process type="org.eclipse.cdt.managedbuilder.core.SetMBSBooleanOptionValue"> <simple name="projectName" value="$(projectName)" /> <complex-array name="resourcePaths"> <element> <simple name="id" value=".*compiler\.option\.warnings\.extrawarn.*" /> <simple name="value" value="true" /> <simple name="path" value="" /> </element> </complex-array> </process>
The identifier is sent from gnu.c.compiler.option.warnings.extrawarn.176373860 to regexp .*compiler\.option\.warnings\.extrawarn.* . The beginning is .* , So this applies to the C and C ++ compiler options, since the C ++ identifier started with gnu.cc.compiler[...] , and I get rid of the end with .* Because the number and suffix unknown to you in template.xml
Next steps
When you're done, see Starting the Eclipse Template in the Template for how to export the plug-in to running Eclipse.