|
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> |
|
2 <html lang="en"> |
|
3 <head> |
|
4 <meta http-equiv="Content-Language" content="en-us"> |
|
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
|
6 <title>Building C/C++ projects</title> |
|
7 <link rel="stylesheet" type="text/css" href="../help.css"> |
|
8 </head> |
|
9 <body> |
|
10 <h1>Building C/C++ projects</h1> |
|
11 <p>The CDT relies on an external make utility, such as GNU make, to |
|
12 build a project. The CDT can generate makefiles automatically when you |
|
13 create a Managed Make C project or a Managed Make C++ project. You have |
|
14 the option of creating a Standard Make C project or a Standard Make C++ |
|
15 project and providing the makefile yourself.</p> |
|
16 <h2>Required utilities</h2> |
|
17 <p>You must install and configure the following utilities: |
|
18 </p> |
|
19 <ul> |
|
20 <li>Build (e.g. make).</li> |
|
21 <li>Compile (e.g. gcc).</li> |
|
22 <li>Debug (e.g. gdb).</li> |
|
23 </ul> |
|
24 <b>Note: </b> while make, gcc and gdb are the examples used in the |
|
25 documentation, virtually any similar set of tools or utilities could be |
|
26 used. |
|
27 <p></p> |
|
28 <p><b>Tip: </b>Cygwin contains these utilities (make, gcc and gdb) for |
|
29 a Windows environment. While running the cygwin installation, |
|
30 ensure <tt>gcc</tt> and <tt>make</tt> are selected since they are not |
|
31 installed by default. For more information, see <a |
|
32 href="http://www.cygwin.com">http://www.cygwin.com</a>. If you are a |
|
33 Red Hat user, all that you need to do to build your project is included |
|
34 in the Red Hat Linux installation. |
|
35 For other operating systems, please refer to your installation |
|
36 documentation.</p> |
|
37 <p></p> |
|
38 <h2>Build terminology</h2> |
|
39 <p>The CDT uses a number of terms to describe the scope of the build. </p> |
|
40 <h3>Build Project</h3> |
|
41 <p>This is an incremental build (make all, assuming all is defined in |
|
42 your makefile). Only the components affected by modified files in that |
|
43 particular project are built.</p> |
|
44 <h3>Rebuild Project</h3> |
|
45 <p>Builds every file in the project whether or not a file has been |
|
46 modified since the last build. A rebuild is a clean followed by a build.</p> |
|
47 <p>For more information on builds, see:</p> |
|
48 <ul> |
|
49 <li><b>Workbench User Guide > Concepts > Workbench > Builds</b></li> |
|
50 <li><b>Workbench User Guide > Tasks > Building resources</b></li> |
|
51 </ul> |
|
52 <p>Build-related information is displayed as follows:</p> |
|
53 <ul> |
|
54 <li>The Console view displays the output of the build tools.</li> |
|
55 <li>The Tasks view displays a list of compiler errors and warnings |
|
56 related to your projects.</li> |
|
57 <li>For Standard Make projects, the Makefile targets are displayed in |
|
58 the Make Targets view.</li> |
|
59 </ul> |
|
60 <p>For more information about the Tasks view, see <b>Workbench User |
|
61 Guide > Reference > User interface information > Views and |
|
62 editors > Tasks view</b>.</p> |
|
63 |
|
64 <h2>Getting a makefile</h2> |
|
65 <p>You can either create a C/C++ project for which you supply the <b>makefile</b> |
|
66 or create a C/C++ project for which the CDT generates makefiles |
|
67 automatically.</p> |
|
68 <p>To create a new project, from the menu bar choose <b>File > New |
|
69 > Project</b>. In the dialog that appears, expand the C/C++ group |
|
70 and choose e.g. C Project</p> |
|
71 <ul> |
|
72 <li>In the resulting wizard page, to create a project for which you supply the <b>makefile</b>, |
|
73 select <b>Makefile project</b> and choose one of the alternatives under that. |
|
74 An empty project, or a simple "Hello World" can be created. |
|
75 You edit and manage the makefile yourself. |
|
76 <p> </p> |
|
77 </li> |
|
78 <li>To create a project for which the CDT supplies a basic <b>makefile</b>, |
|
79 select another project type, e.g. <b>Executable</b> and choose one of the examples |
|
80 under that, or choose <b>Empty Project</b>. |
|
81 </li> |
|
82 </ul> |
|
83 <h2>Setting build preferences</h2> |
|
84 <p>You can set build preferences in Eclipse:</p> |
|
85 <dl> |
|
86 <dt>Build order</dt> |
|
87 <dd>If certain projects must be built before others, you can set the <i>build |
|
88 order</i>. If your project refers to another project, the CDT must |
|
89 build the other project first. To set the build order, from the menu |
|
90 bar select <b>Window > Preferences</b> and choose <b> General > Preferences > Build Order</b>. |
|
91 <p>When you set the build order, the CDT does not rebuild projects |
|
92 that depend on a project; you must rebuild all projects to ensure all |
|
93 changes are propagated.</p> |
|
94 </dd> |
|
95 <dt>Automatic save</dt> |
|
96 <dd>You can set the CDT to perform an <i>automatic save</i> of all |
|
97 modified resources when you perform a manual build. In the preferences dialog, |
|
98 select <b>General > Workspace</b> and check <b>Save automatically before build</b>. |
|
99 By default, |
|
100 this feature is <i>not</i> enabled.</dd> |
|
101 </dl> |
|
102 |
|
103 <h2>Controlling the building of your project</h2> |
|
104 <p>For a Makefile project, the C/C++ compiler that a project uses |
|
105 is controlled by the project's <b>Properties</b> setting. |
|
106 To view a project's properties, right-click on the project and select <b>Properties</b>. |
|
107 In the dialog that appears, the <b>C/C++ Build</b> |
|
108 page enables you to control a variety of settings, including:</p> |
|
109 <dl> |
|
110 <dt>Build Command</dt> |
|
111 <dd>On the <b>Builder Settings</b> tab, this controls which <code>make</code> is used. To change it, uncheck <b>Use |
|
112 default build command</b> and change it or add arguments to the make command.</dd> |
|
113 |
|
114 <dt>Build Setting</dt> |
|
115 <dd>On the <b>Behaviour</b> tab, this controls whether the compiler will <b>Stop on first build error</b> or not |
|
116 (keep going). Unchecking <b>Stop on first build error</b> will force the compiler to attempt to build all referenced |
|
117 projects even if the current project has errors.</dd> |
|
118 |
|
119 <dt>Workbench Build Behavior</dt> |
|
120 <dd>On the <b>Behaviour </b> tab, this controls which makefile target will be built depending on the scope of the |
|
121 build, e.g. <code>all</code> or <code>clean</code>.</dd> |
|
122 </dl> |
|
123 <p>For a standard (non-Makefile) project (often called "Managed Build" or "Managed Make" project from |
|
124 earlier CDT version), the project properties dialog enables |
|
125 you to manage the build configurations of your project. For additional |
|
126 information see:</p> |
|
127 <ul> |
|
128 <li><b>Reference > C/C++ Properties > C/C++ Project Properties > Managed Make |
|
129 Projects</b></li> |
|
130 <li><b>Reference > C/C++ Properties > C/C++ Project Properties > Managed Make File |
|
131 Properties</b></li> |
|
132 </ul> |
|
133 <h2>Viewing build information</h2> |
|
134 <p>Build-related information is displayed as follows: </p> |
|
135 <ul> |
|
136 <li>The <b>Console</b> view displays the output of the make utility.</li> |
|
137 <li>The <b>Tasks</b> view displays a list of compiler errors and |
|
138 warnings related to your projects. </li> |
|
139 <li>For a Standard Make project, build actions display in the <b>Make |
|
140 Targets</b> view.</li> |
|
141 </ul> |
|
142 <p><img border="0" src="../images/ngconcepts.gif" alt="Related concepts" |
|
143 width="143" height="21"> |
|
144 <br> |
|
145 <a href="cdt_c_projects.htm">CDT Projects</a><br> |
|
146 <a href="cdt_c_proj_file_views.htm">Project file views</a></p> |
|
147 <p><img border="0" src="../images/ngtasks.gif" alt="Related tasks" |
|
148 width="143" height="21"> |
|
149 <br> |
|
150 <a href="../tasks/cdt_o_build_task.htm">Building projects</a></p> |
|
151 <p><img border="0" src="../images/ngref.gif" alt="Related reference" |
|
152 width="143" height="21"> |
|
153 <br> |
|
154 <a href="../reference/cdt_u_properties.htm">Project Properties</a></p> |
|
155 |
|
156 <p><img src="../images/rh03_04.gif" alt="Red Hat Copyright Statement"><br> |
|
157 <img src="../images/ng00_04a.gif" alt="IBM Copyright Statement"> |
|
158 </p> |
|
159 </body> |
|
160 </html> |