share
Stack OverflowBuild several CDT C++ projects from commandline
[+38] [5] Rüdiger Stevens
[2008-12-05 18:55:53]
[ eclipse command-line eclipse-cdt ]
[ https://stackoverflow.com/questions/344797/build-several-cdt-c-projects-from-commandline ]

What is the best solution to build several CDT C++ projects from the command line? The projects have references and so it is not possible to just build single projects.

(1) Have you considered using Make? - Lawand
(1) Make uses the .mk files generated by CDT on build. So it isn't possible to build the project from scratch. - mmmmmmmm
(4) This is one of the big weaknesses of Eclipse in general, I think. Headless builds are not a first class citizen in the Eclipse world. - JesperE
[+65] [2009-06-07 19:22:05] James Blackburn

This feature has been added in CDT 6 (Final build due June 15th 2009). You can download the final release candidate from builds page: download.eclipse.org/tools/cdt/builds/6.0.0/.

Using a release of Eclipse 3.5 + CDT 6, you can import, build and clean-build projects and the workspace using the following options sent to Eclipse at the command line:

eclipse -nosplash 
        -application org.eclipse.cdt.managedbuilder.core.headlessbuild 
        -import {[uri:/]/path/to/project} 
        -build {project_name | all} 
        -cleanBuild {projec_name | all}

On Windows, use eclipsec.exe [1] instead of eclipse.exe to have build output written to stdout/stderr and so that the call blocks until completion.

The '-application' switch instructs Eclipse to run the CDT headless builder rather than starting the workbench. The other switches can be used individually or together. This means you can checkout a project using a shell script of your own, '-import' it into a workspace, and '-build' it using the Managedbuilder's headless builder.

Use the '-data' switch to specify the workspace to use, which can be an empty temporary directory, see the runtime documentation for other switches supported by the platform runtime: help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html [2]

See bug 186847 comment 24 [3] and onwards for more detail on the committed functionality.

[1] https://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F
[2] http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html
[3] https://bugs.eclipse.org/bugs/show_bug.cgi?id=186847#c24

(2) In addition, you can specify a single configuration with: -build {project_name[/config_name] | all} Example: -build project_name/Release - Alejandro Blasco
1
[+1] [2009-06-07 19:57:47] James Blackburn

Pre CDT 6 you could use the JDT's AptBuilder [1] (included with classic Eclipse, for example).

This lets you build an already configured workspace. So you: checkout your source, configure a workspace which points to the checked-out projects. Your automated build scripts can then update the checkouts and run the AptBuilder without needing to start the GUI.

[1] http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/apt/org/eclipse/jdt/apt/core/build/package-summary.html

2
[0] [2009-01-05 18:29:10] Paulo Lopes

If you created a Make project under CDT you can just use your favorite shell and execute make in all the projects dirs.


This is the answer to your question. You need to "mess around with Makefiles". Eclipse is not a build system. - Jesse Weigert
(3) @Jesse: This is only a half answer. And it wouldn't be an answer if I had written that our projects are not Make projects. Because changing the pre-conditions of a question is not the answer to it. - mmmmmmmm
(3) New URL for @JesseWeigert comment is: blog.codinghorror.com/the-f5-key-is-not-a-build-process - Jonah Graham
3
[0] [2009-05-29 19:47:15] lothar

Headless build with the manage builder is currently not supported, see bug 186847 - CDT internal builder does not support automated command line builds [1].

If you use the unmanaged (make) builder, then you already have Makefiles that you can use from the command line.

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=186847

(6) This is no longer true. That bug has been fixed. - Christopher Barber
4
[-1] [2009-01-05 21:31:25] Jeff Lamb

We do this in our existing build.

Put a makefile in all your external references and your toplevel project. In your "all" rule, have it run: make -C ./externalref1 make -C ./externalref2 etc

we actually define the external dependencies in a variable: EXT_DEP = externalref1 externalref2 then use the subst (substitute) command to kick off all the sub-makes using the correct call.


5