Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: native_client_sdk/src/doc/_developer.chrome.com_generated/devguide/devcycle/building.html

Issue 140993006: [NaCl SDK Docs] Check in the generated NaCl SDK Documentation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: try without pepper_{dev,beta,stable} Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 {{+bindTo:partials.standard_nacl_article}}
2
3 <section id="building">
4 <span id="devcycle-building"></span><h1 id="building"><span id="devcycle-buildin g"></span>Building</h1>
5 <div class="contents local topic" id="table-of-contents">
6 <p class="topic-title first">Table Of Contents</p>
7 <ul class="small-gap">
8 <li><p class="first"><a class="reference internal" href="#introduction" id="id4" >Introduction</a></p>
9 <ul class="small-gap">
10 <li><a class="reference internal" href="#target-architectures" id="id5">Target a rchitectures</a></li>
11 <li><a class="reference internal" href="#c-libraries" id="id6">C libraries</a></ li>
12 <li><a class="reference internal" href="#c-standard-libraries" id="id7">C++ stan dard libraries</a></li>
13 <li><a class="reference internal" href="#sdk-toolchains" id="id8">SDK toolchains </a></li>
14 <li><a class="reference internal" href="#sdk-toolchains-versus-your-hosted-toolc hain" id="id9">SDK toolchains versus your hosted toolchain</a></li>
15 </ul>
16 </li>
17 <li><a class="reference internal" href="#the-pnacl-toolchain" id="id10">The PNaC l toolchain</a></li>
18 <li><p class="first"><a class="reference internal" href="#using-the-pnacl-tools- to-compile-link-debug-and-deploy" id="id11">Using the PNaCl tools to compile, li nk, debug, and deploy</a></p>
19 <ul class="small-gap">
20 <li><a class="reference internal" href="#compile" id="id12">Compile</a></li>
21 <li><a class="reference internal" href="#create-a-static-library" id="id13">Crea te a static library</a></li>
22 <li><a class="reference internal" href="#link-the-application" id="id14">Link th e application</a></li>
23 <li><a class="reference internal" href="#finalizing-the-pexe-for-deployment" id= "id15">Finalizing the <strong>pexe</strong> for deployment</a></li>
24 </ul>
25 </li>
26 <li><p class="first"><a class="reference internal" href="#the-gnu-based-toolchai ns" id="id16">The GNU-based toolchains</a></p>
27 <ul class="small-gap">
28 <li><a class="reference internal" href="#compiling" id="id17">Compiling</a></li>
29 <li><a class="reference internal" href="#creating-libraries-and-linking" id="id1 8">Creating libraries and Linking</a></li>
30 <li><a class="reference internal" href="#finalizing-a-nexe-for-deployment" id="i d19">Finalizing a <strong>nexe</strong> for deployment</a></li>
31 </ul>
32 </li>
33 <li><a class="reference internal" href="#using-make" id="id20">Using make</a></l i>
34 <li><a class="reference internal" href="#libraries-and-header-files-provided-wit h-the-sdk" id="id21">Libraries and header files provided with the SDK</a></li>
35 <li><p class="first"><a class="reference internal" href="#troubleshooting" id="i d22">Troubleshooting</a></p>
36 <ul class="small-gap">
37 <li><a class="reference internal" href="#undefined-reference-error" id="id23">&# 8220;Undefined reference&#8221; error</a></li>
38 <li><a class="reference internal" href="#can-t-find-libraries-containing-necessa ry-symbols" id="id24">Can&#8217;t find libraries containing necessary symbols</a ></li>
39 <li><a class="reference internal" href="#pnacl-abi-verification-errors" id="id25 ">PNaCl ABI Verification errors</a></li>
40 </ul>
41 </li>
42 </ul>
43 </div>
44 <section id="introduction">
45 <h2 id="introduction">Introduction</h2>
46 <p>This document describes how to build Native Client modules. It is intended fo r
47 developers who have experience writing, compiling, and linking C and C++ code.
48 If you haven&#8217;t read the Native Client <a class="reference internal" href=" /native-client/overview.html"><em>Technical Overview</em></a> and <a class="refe rence internal" href="/native-client/devguide/tutorial/index.html"><em>Tutorial< /em></a>, we recommend starting
49 with those.</p>
50 <section id="target-architectures">
51 <span id="id1"></span><h3 id="target-architectures"><span id="id1"></span>Target architectures</h3>
52 <p>Portable Native Client (PNaCl) modules are written in C or C++ and compiled
53 into an executable file ending in a <strong>.pexe</strong> extension using the P NaCl
54 toolchain in the Native Client SDK. Chrome can load <strong>pexe</strong> files
55 embedded in web pages and execute them as part of a web application.</p>
56 <p>As explained in the Technical Overview, PNaCl modules are
57 operating-system-independent <strong>and</strong> processor-independent. The sam e
58 <strong>pexe</strong> will run on Windows, Mac, Linux, and ChromeOS and it will run on
59 any processor, e.g., x86-32, x86-64, and ARM.</p>
60 <p>Native Client also supports architecture-specific <strong>nexe</strong> files .
61 These <strong>nexe</strong> files are <strong>also</strong> operating-system-ind ependent,
62 but they are <strong>not</strong> processor-independent. To support a wide varie ty of
63 devices you must compile separate versions of your Native Client module
64 for different processors on end-user machines. A
65 <a class="reference internal" href="/native-client/overview.html#application-fil es"><em>manifest file</em></a> will then specify which version
66 of the module to load based on the end-user&#8217;s architecture. The SDK
67 includes a script&#8212;<code>create_nmf.py</code> (in the <code>tools/</code> d irectory)&#8212;to
68 generate manifest files. For examples of how to compile modules
69 for multiple target architectures and how to generate manifest files, see the
70 Makefiles included with the SDK examples.</p>
71 <p>This section will mostly cover PNaCl, but also describes how to build
72 nexe applications.</p>
73 </section><section id="c-libraries">
74 <h3 id="c-libraries">C libraries</h3>
75 <p>The PNaCl SDK has a single choice of C library: <a class="reference external" href="http://sourceware.org/newlib/">newlib</a>.</p>
76 <p>The Native Client SDK also has a GCC-based toolchain for building
77 <strong>nexes</strong>. The GCC-based toolchain has support for two C libraries:
78 <a class="reference external" href="http://sourceware.org/newlib/">newlib</a> an d <a class="reference external" href="http://www.gnu.org/software/libc/">glibc</ a>. See <a class="reference internal" href="/native-client/devguide/devcycle/dy namic-loading.html"><em>Dynamic Linking &amp; Loading with glibc</em></a> for in formation about these libraries, including factors to
79 help you decide which to use.</p>
80 </section><section id="c-standard-libraries">
81 <span id="building-cpp-libraries"></span><h3 id="c-standard-libraries"><span id= "building-cpp-libraries"></span>C++ standard libraries</h3>
82 <p>The PNaCl SDK can use either LLVM&#8217;s <a class="reference external" href= "http://libcxx.llvm.org/">libc++</a>
83 (the current default) or GCC&#8217;s <a class="reference external" href="http:// gcc.gnu.org/libstdc++">libstdc++</a> (deprecated). The
84 <code>-stdlib=[libc++|libstdc++]</code> command line argument can be used to
85 choose which standard library to use.</p>
86 <p>The GCC-based Native Client SDK only has support for GCC&#8217;s <a class="re ference external" href="http://gcc.gnu.org/libstdc++">libstdc++</a>.</p>
87 <p>C++11 library support is only complete in libc++ but other non-library
88 language features should work regardless of which standard library is
89 used. The <code>-std=[c++98|c++11]</code> command line argument can be used to
90 indicate which C++ language standard to use (or <code>-std=gnu++11</code> to
91 access non-standard extensions).</p>
92 </section><section id="sdk-toolchains">
93 <h3 id="sdk-toolchains">SDK toolchains</h3>
94 <p>The Native Client SDK includes multiple toolchains. It has one PNaCl toolchai n
95 and it has multiple GCC-based toolchains that are differentiated by target
96 architectures and C libraries. The single PNaCl toolchain is located
97 in a directory named <code>toolchain/&lt;OS_platform&gt;_pnacl</code>, and the G CC-based
98 toolchains are located in directories named
99 <code>toolchain/&lt;OS_platform&gt;_&lt;architecture&gt;_&lt;library&gt;</code>, where:</p>
100 <ul class="small-gap">
101 <li><em>&lt;platform&gt;</em> is the platform of your development machine (win, mac, or linux)</li>
102 <li><em>&lt;architecture&gt;</em> is your target architecture (x86 or arm)</li>
103 <li><em>&lt;library&gt;</em> is the C library you are compiling with (newlib or glibc)</li>
104 </ul>
105 <p>The compilers, linkers, and other tools are located in the <code>bin/</code>
106 subdirectory in each toolchain. For example, the tools in the Windows SDK
107 for PNaCl has a C++ compiler in <code>toolchain/win_pnacl/bin/pnacl-clang++</cod e>.
108 As another example, the GCC-based C++ compiler that targets the x86 and uses the
109 newlib library, is located at <code>toolchain/win_x86_newlib/bin/x86_64-nacl-g++ </code>.</p>
110 <aside class="note">
111 The SDK toolchains descend from the <code>toolchain/</code> directory. The SDK a lso
112 has a <code>tools/</code> directory; this directory contains utilities that are not
113 properly part of the toolchains but that you may find helpful in building and
114 testing your application (e.g., the <code>create_nmf.py</code> script, which you can
115 use to create a manifest file).
116 </aside>
117 </section><section id="sdk-toolchains-versus-your-hosted-toolchain">
118 <h3 id="sdk-toolchains-versus-your-hosted-toolchain">SDK toolchains versus your hosted toolchain</h3>
119 <p>To build NaCl modules, you must use one of the Native Client toolchains
120 included in the SDK. The SDK toolchains use a variety of techniques to
121 ensure that your NaCl modules comply with the security constraints of
122 the Native Client sandbox.</p>
123 <p>During development, you have another choice: You can build modules using a
124 <em>standard</em> toolchain, such as the hosted toolchain on your development
125 machine. This can be Visual Studio&#8217;s standard compiler, XCode, LLVM, or
126 GNU-based compilers on your development machine. These standard toolchains
127 will not produce executables that comply with the Native Client sandbox
128 security constraints. They are also not portable across operating systems
129 and not portable across different processors. However, using a standard
130 toolchain allows you to develop modules in your favorite IDE and use
131 your favorite debugging and profiling tools. The drawback is that modules
132 compiled in this manner can only run as Pepper (PPAPI) plugins in Chrome.
133 To publish and distribute Native Client modules as part of a web
134 application, you must eventually use a toolchain in the Native
135 Client SDK.</p>
136 <aside class="note">
137 In the future, additional tools will be available to compile Native Client
138 modules written in other programming languages, such as C#. But this
139 document covers only compiling C and C++ code, using the toolchains
140 provided in the SDK.
141 </aside>
142 </section></section><section id="the-pnacl-toolchain">
143 <h2 id="the-pnacl-toolchain">The PNaCl toolchain</h2>
144 <p>The PNaCl toolchain contains modified versions of the tools in the
145 LLVM toolchain, as well as linkers and other tools from binutils.
146 To determine which version of LLVM or binutils the tools are based upon,
147 run the tool with the <code>--version</code> command line flag. These tools
148 are used to compile and link applications into .pexe files. The toolchain
149 also contains a tool to translate a .pexe file into a
150 architecture-specific .nexe (e.g., for debugging purposes).</p>
151 <p>Each tool&#8217;s name is preceded by the prefix &#8220;pnacl-&#8221;. Some o f the useful
152 tools include:</p>
153 <dl class="docutils">
154 <dt>pnacl-abicheck</dt>
155 <dd>Check that the <strong>pexe</strong> follows the PNaCl ABI rules.</dd>
156 <dt>pnacl-ar</dt>
157 <dd>Creates archives (i.e., static libraries)</dd>
158 <dt>pnacl-clang</dt>
159 <dd>C compiler and compiler driver</dd>
160 <dt>pnacl-clang++</dt>
161 <dd>C++ compiler and compiler driver</dd>
162 <dt>pnacl-dis</dt>
163 <dd>Disassembler for both <strong>pexe</strong> files and <strong>nexe</strong> files</dd>
164 <dt>pnacl-finalize</dt>
165 <dd>Finalizes <strong>pexe</strong> files for deployment</dd>
166 <dt>pnacl-ld</dt>
167 <dd>Bitcode linker</dd>
168 <dt>pnacl-nm</dt>
169 <dd>Lists symbols in bitcode files, native code, and libraries</dd>
170 <dt>pnacl-ranlib</dt>
171 <dd>Generates a symbol table for archives (i.e., static libraries)</dd>
172 <dt>pnacl-translate</dt>
173 <dd>Translates a <strong>pexe</strong> to a native architecture, outside of the browser</dd>
174 </dl>
175 <p>For the full list of tools, see the
176 <code>&lt;NACL_SDK_ROOT&gt;/toolchain/&lt;platform&gt;_pnacl/bin</code> director y.</p>
177 </section><section id="using-the-pnacl-tools-to-compile-link-debug-and-deploy">
178 <h2 id="using-the-pnacl-tools-to-compile-link-debug-and-deploy">Using the PNaCl tools to compile, link, debug, and deploy</h2>
179 <p>To build an application with the PNaCl SDK toolchain, you must compile
180 your code, link it, test and debug it, and then deploy it. This section goes
181 over some examples of how to use the tools.</p>
182 <section id="compile">
183 <h3 id="compile">Compile</h3>
184 <p>To compile a simple application consisting of <code>file1.cc</code> and <code >file2.cc</code> into
185 <code>hello_world.pexe</code> with a single command, use the <code>pnacl-clang++ </code> tool</p>
186 <pre>
187 &lt;NACL_SDK_ROOT&gt;/toolchain/win_pnacl/bin/pnacl-clang++ file1.cc file2.cc ^
188 -I&lt;NACL_SDK_ROOT&gt;/include -L&lt;NACL_SDK_ROOT&gt;/lib/pnacl/Release ^
189 -o hello_world.pexe -g -O2 -lppapi_cpp -lppapi
190 </pre>
191 <p>(The carat <code>^</code> allows the command to span multiple lines on Window s;
192 to do the same on Mac and Linux use a backslash instead. Or you can
193 simply type the command and all its arguments on one
194 line. <code>&lt;NACL_SDK_ROOT&gt;</code> represents the path to the top-level
195 directory of the bundle you are using, e.g.,
196 <code>&lt;location-where-you-installed-the-SDK&gt;/pepper_31</code>.)</p>
197 <p>However, the typical application consists of many files. In that case,
198 each file can be compiled separately so that only files that are
199 affected by a change need to be recompiled. To compile an individual
200 file from your application, you must use either the <code>pnacl-clang</code> C
201 compiler, or the <code>pnacl-clang++</code> C++ compiler. The compiler produces
202 separate bitcode files. For example:</p>
203 <pre>
204 &lt;NACL_SDK_ROOT&gt;/toolchain/win_pnacl/bin/pnacl-clang++ hello_world.cc ^
205 -I&lt;NACL_SDK_ROOT&gt;/include -c -o hello_world.o -g -O0
206 </pre>
207 <p>For a description of each command line flag, run <code>pnacl-clang --help</co de>.
208 For convenience, here is a description of some of the flags used in
209 the example.</p>
210 <dl class="docutils" id="compile-flags">
211 <dt><code>-c</code></dt>
212 <dd>indicates that <code>pnacl-clang++</code> should only compile an individual file,
213 rather than continue the build process and link together the
214 full application.</dd>
215 <dt><code>-o &lt;output_file&gt;</code></dt>
216 <dd>indicates the <strong>output</strong> filename.</dd>
217 <dt><code>-g</code></dt>
218 <dd>tells the compiler to include debug information in the result.
219 This debug information can be used during development, and then <strong>stripped </strong>
220 before actually deploying the application to keep the application&#8217;s
221 download size small.</dd>
222 <dt><code>-On</code></dt>
223 <dd><p class="first">sets the optimization level to n. Use 0 when debugging, and -O2 or -O3
224 for profiling and deployment.</p>
225 <p class="last">The main difference between -O2 and -O3 is whether the compiler performs
226 optimizations that involve a space-speed tradeoff. It could be the case that
227 <code>-O3</code> optimizations are not desirable due to increased <strong>pexe</ strong>
228 download size; you should make your own performance measurements to determine
229 which level of optimization is right for you. When looking at code size,
230 note that what you generally care about is not the size of the pexe
231 produced by pnacl-clang, but the size of the compressed pexe that you upload
232 your application to the server or to the Chrome Web Store.
233 Optimizations that increase the size of a pexe may not increase the size of
234 the compressed pexe that much.</p>
235 </dd>
236 <dt><code>-I&lt;directory&gt;</code></dt>
237 <dd>adds a directory to the search path for <strong>include</strong> files. The SDK has
238 Pepper (PPAPI) headers located at <code>&lt;NACL_SDK_ROOT&gt;/include</code>, so add
239 that directory when compiling to be able to include the headers.</dd>
240 </dl>
241 </section><section id="create-a-static-library">
242 <h3 id="create-a-static-library">Create a static library</h3>
243 <p>The <code>pnacl-ar</code> and <code>pnacl-ranlib</code> tools allow you to cr eate a
244 <strong>static</strong> library from a set of bitcode files, which can later be linked
245 into the full application.</p>
246 <pre>
247 &lt;NACL_SDK_ROOT&gt;/toolchain/win_pnacl/bin/pnacl-ar cr libfoo.a ^
248 foo1.o foo2.o foo3.o
249
250 &lt;NACL_SDK_ROOT&gt;/toolchain/win_pnacl/bin/pnacl-ranlib libfoo.a
251 </pre>
252 </section><section id="link-the-application">
253 <h3 id="link-the-application">Link the application</h3>
254 <p>The <code>pnacl-clang++</code> tool is used to compile applications, but it c an
255 also be used link together compiled bitcode and libraries into a
256 full application.</p>
257 <pre>
258 &lt;NACL_SDK_ROOT&gt;/toolchain/win_pnacl/bin/pnacl-clang++ -o hello_world.pexe ^
259 hello_world.o -L&lt;NACL_SDK_ROOT&gt;/lib/pnacl/Debug -lfoo -lppapi_cpp -lppap i
260 </pre>
261 <p>This links the hello world bitcode with the <code>foo</code> library in the e xample
262 as well as the <em>Debug</em> version of the Pepper libraries which are located
263 in <code>&lt;NACL_SDK_ROOT&gt;/lib/pnacl/Debug</code>. If you wish to link again st the
264 <em>Release</em> version of the Pepper libraries, change the
265 <code>-L&lt;NACL_SDK_ROOT&gt;/lib/pnacl/Debug</code> to
266 <code>-L&lt;NACL_SDK_ROOT&gt;/lib/pnacl/Release</code>.</p>
267 </section><section id="finalizing-the-pexe-for-deployment">
268 <h3 id="finalizing-the-pexe-for-deployment">Finalizing the <strong>pexe</strong> for deployment</h3>
269 <p>Typically you would run the application to test it and debug it if needed
270 before deploying. See the <a class="reference internal" href="/native-client/dev guide/devcycle/running.html"><em>running</em></a> documentation for how
271 to run a PNaCl application, and see the <a class="reference internal" href="/nat ive-client/devguide/devcycle/debugging.html"><em>debugging</em></a>
272 documentation for debugging techniques and workflow. After testing a PNaCl
273 application, you must <strong>&#8220;finalize&#8221;</strong> it. The <code>pnac l-finalize</code>
274 tool handles this.</p>
275 <pre>
276 &lt;NACL_SDK_ROOT&gt;/toolchain/win_pnacl/bin/pnacl-finalize ^
277 hello_world.pexe -o hello_world.final.pexe
278 </pre>
279 <p>Prior to finalization, the application <strong>pexe</strong> is stored in a b inary
280 format that is subject to change. After finalization, the application
281 pexe is <strong>rewritten</strong> into a different binary format that is <stron g>stable</strong>
282 and will be supported by future versions of PNaCl. The finalization step
283 also helps minimize the size of your application for distribution by
284 stripping out debug information and other metadata.</p>
285 <p>Once the application is finalized, be sure to adjust the manifest file to
286 refer to the final version of the application before deployment.
287 The <code>create_nmf.py</code> tool helps generate an <code>.nmf</code> file, bu t <code>.nmf</code>
288 files can also be written by hand.</p>
289 </section></section><section id="the-gnu-based-toolchains">
290 <h2 id="the-gnu-based-toolchains">The GNU-based toolchains</h2>
291 <p>Besides the PNaCl toolchain, the Native Client SDK also includes modified
292 versions of the tools in the standard GNU toolchain, including the GCC
293 compilers and the linkers and other tools from binutils. These tools only
294 support building <strong>nexe</strong> files. Run the tool with the <code>--vers ion</code>
295 command line flag to determine the current version of the tools.</p>
296 <p>Each tool in the toolchain is prefixed with the name of the target
297 architecture. In the toolchain for the ARM target architecture, each
298 tool&#8217;s name is preceded by the prefix &#8220;arm-nacl-&#8221;. In the tool chains for
299 the x86 target architecture, there are actually two versions of each
300 tool&#8212;one to build Native Client modules for the x86-32
301 target architecture, and one to build modules for the x86-64 target
302 architecture. &#8220;i686-nacl-&#8221; is the prefix for tools used to build
303 32-bit .nexes, and &#8220;x86_64-nacl-&#8221; is the prefix for tools used to
304 build 64-bit .nexes</p>
305 <p>These prefixes conform to gcc naming standards and make it easy to use tools
306 like autoconf. As an example, you can use <code>i686-nacl-gcc</code> to compile 32-bit
307 .nexes, and <code>x86_64-nacl-gcc</code> to compile 64-bit .nexes. Note that you can
308 typically override a tool&#8217;s default target architecture with command line
309 flags, e.g., you can specify <code>x86_64-nacl-gcc -m32</code> to compile a 32-b it
310 .nexe.</p>
311 <p>The GNU-based SDK toolchains include the following tools:</p>
312 <ul class="small-gap">
313 <li>&lt;prefix&gt;addr2line</li>
314 <li>&lt;prefix&gt;ar</li>
315 <li>&lt;prefix&gt;as</li>
316 <li>&lt;prefix&gt;c++</li>
317 <li>&lt;prefix&gt;c++filt</li>
318 <li>&lt;prefix&gt;cpp</li>
319 <li>&lt;prefix&gt;g++</li>
320 <li>&lt;prefix&gt;gcc</li>
321 <li>&lt;prefix&gt;gcc-4.4.3</li>
322 <li>&lt;prefix&gt;gccbug</li>
323 <li>&lt;prefix&gt;gcov</li>
324 <li>&lt;prefix&gt;gprof</li>
325 <li>&lt;prefix&gt;ld</li>
326 <li>&lt;prefix&gt;nm</li>
327 <li>&lt;prefix&gt;objcopy</li>
328 <li>&lt;prefix&gt;objdump</li>
329 <li>&lt;prefix&gt;ranlib</li>
330 <li>&lt;prefix&gt;readelf</li>
331 <li>&lt;prefix&gt;size</li>
332 <li>&lt;prefix&gt;strings</li>
333 <li>&lt;prefix&gt;strip</li>
334 </ul>
335 <section id="compiling">
336 <h3 id="compiling">Compiling</h3>
337 <p>Compiling files with the GNU-based toolchain is similar to compiling
338 files with the PNaCl-based toolchain, except that the output is
339 architecture specific.</p>
340 <p>For example, assuming you&#8217;re developing on a Windows machine, targeting the x86
341 architecture, and using the newlib library, you can compile a 32-bit .nexe for
342 the hello_world example with the following command:</p>
343 <pre>
344 &lt;NACL_SDK_ROOT&gt;/toolchain/win_x86_newlib/bin/i686-nacl-gcc hello_world.c ^
345 -I&lt;NACL_SDK_ROOT&gt;/include -L&lt;NACL_SDK_ROOT&gt;/lib/newlib/Release ^
346 -o hello_world_x86_32.nexe -m32 -g -O2 -lppapi
347 </pre>
348 <p>To compile a 64-bit .nexe, you can run the same command but use -m64 instead of
349 -m32. Alternatively, you could also use the version of the compiler that
350 targets the x86-64 architecture, i.e., <code>x86_64-nacl-gcc</code>.</p>
351 <p>You should name executable modules with a <strong>.nexe</strong> filename ext ension,
352 regardless of what platform you&#8217;re using.</p>
353 </section><section id="creating-libraries-and-linking">
354 <h3 id="creating-libraries-and-linking">Creating libraries and Linking</h3>
355 <p>Creating libraries and linking with the GNU-based toolchain is similar
356 to doing the same with the PNaCl toolchain. The relevant tools
357 for creating <strong>static</strong> libraries are <code>&lt;prefix&gt;ar</code> and <code>&lt;prefix&gt;ranlib</code>.
358 Linking can be done with <code>&lt;prefix&gt;g++</code>. See the
359 <a class="reference internal" href="/native-client/devguide/devcycle/dynamic-loa ding.html"><em>Dynamic Linking &amp; Loading with glibc</em></a>
360 section on how to create <strong>shared</strong> libraries.</p>
361 </section><section id="finalizing-a-nexe-for-deployment">
362 <h3 id="finalizing-a-nexe-for-deployment">Finalizing a <strong>nexe</strong> for deployment</h3>
363 <p>Unlike the PNaCl toolchain, no separate finalization step is required
364 for <strong>nexe</strong> files. The nexe files are always in a <strong>stable</ strong> format.
365 However, the nexe file may contain debug information and symbol information
366 which may make the nexe file larger than needed for distribution.
367 To minimize the size of the distributed file, you can run the
368 <code>&lt;prefix&gt;strip</code> tool to strip out debug information.</p>
369 </section></section><section id="using-make">
370 <h2 id="using-make">Using make</h2>
371 <p>This document doesn&#8217;t cover how to use <code>make</code>, but if you wa nt to use
372 <code>make</code> to build your Native Client module, you can base your Makefile on the
373 ones in the SDK examples.</p>
374 <p>The Makefiles for the SDK examples build most of the examples in multiple
375 configurations (using PNaCl vs NaCl, using different C libraries,
376 targeting different architectures, and using different levels of optimization).
377 To select a specific toolchain, set the <strong>environment variable</strong>
378 <code>TOOLCHAIN</code> to either <code>pnacl</code>, <code>newlib</code>, <code> glibc</code>, or <code>host</code>.
379 To select a specific level of optimization set the <strong>environment
380 variable</strong> <code>CONFIG</code> to either <code>Debug</code>, or <code>Rel ease</code>. Running
381 <code>make</code> in each example&#8217;s directory does <strong>one</strong> of the following,
382 depending on the setting of the environment variables.</p>
383 <ul class="small-gap">
384 <li><p class="first">If <code>TOOLCHAIN=pnacl</code> creates a subdirectory call ed <code>pnacl</code>;</p>
385 <ul class="small-gap">
386 <li>builds a .pexe (architecture-independent Native Client executable) using
387 the newlib library</li>
388 <li>generates a Native Client manifest (.nmf) file for the pnacl version of the
389 example</li>
390 </ul>
391 </li>
392 <li><p class="first">If <code>TOOLCHAIN=newlib</code> creates a subdirectory cal led <code>newlib</code>;</p>
393 <ul class="small-gap">
394 <li>builds .nexes for the x86-32, x86-64, and ARM architectures using the
395 newlib library</li>
396 <li>generates a Native Client manifest (.nmf) file for the newlib version of
397 the example</li>
398 </ul>
399 </li>
400 <li><p class="first">If <code>TOOLCHAIN=glibc</code> creates a subdirectory call ed <code>glibc</code>;</p>
401 <ul class="small-gap">
402 <li>builds .nexes for the x86-32 and x86-64 architectures using the glibc
403 library</li>
404 <li>generates a Native Client manifest (.nmf) file for the glibc version of the
405 example</li>
406 </ul>
407 </li>
408 <li><p class="first">If <code>TOOLCHAIN=host</code> creates a subdirectory calle d <code>windows</code>, <code>linux</code>,
409 or <code>mac</code> (depending on your development machine);</p>
410 <ul class="small-gap">
411 <li>builds a Pepper plugin (.dll for Windows, .so for Linux/Mac) using the
412 hosted toolchain on your development machine</li>
413 <li>generates a Native Client manifest (.nmf) file for the host Pepper plugin
414 version of the example</li>
415 </ul>
416 </li>
417 </ul>
418 <aside class="note">
419 The glibc library is not yet available for the ARM and PNaCl toolchains.
420 </aside>
421 <p>Here is how to build the examples with PNaCl in Release mode on Windows.
422 The resulting files for <code>examples/api/audio</code> will be in
423 <code>examples/api/audio/pnacl/Release</code>, and the directory layout is simil ar for
424 other examples.</p>
425 <pre>
426 set TOOLCHAIN=pnacl
427 set CONFIG=Release
428 make
429 </pre>
430 <p>Your Makefile can be simpler since you will not likely want to build so many
431 different configurations of your module. The example Makefiles define
432 numerous variables near the top (e.g., <code>CFLAGS</code>) that make it easy
433 to customize the commands that are executed for your project and the options
434 for each command.</p>
435 <p>For details on how to use make, see the <a class="reference external" href="h ttp://www.gnu.org/software/make/manual/make.html">GNU &#8216;make&#8217; Manual< /a>.</p>
436 </section><section id="libraries-and-header-files-provided-with-the-sdk">
437 <h2 id="libraries-and-header-files-provided-with-the-sdk">Libraries and header f iles provided with the SDK</h2>
438 <p>The Native Client SDK includes modified versions of standard toolchain-suppor t
439 libraries, such as libpthread and libc, plus the relevant header files.
440 The standard libraries are located in the following directories:</p>
441 <ul class="small-gap">
442 <li>PNaCl toolchain: <code>toolchain/&lt;platform&gt;_pnacl/usr/lib</code></li>
443 <li>x86 toolchains: <code>toolchain/&lt;platform&gt;_x86_&lt;library&gt;/x86_64- nacl/lib32</code> and
444 <code>/lib64</code> (for the 32-bit and 64-bit target architectures, respectivel y)</li>
445 <li>ARM toolchain: <code>toolchain/&lt;platform&gt;_arm_&lt;library&gt;/arm-nacl /lib</code></li>
446 </ul>
447 <p>For example, on Windows, the libraries for the x86-64 architecture in the
448 newlib toolchain are in <code>toolchain/win_x86_newlib/x86_64-nacl/lib64</code>. </p>
449 <p>The header files are in:</p>
450 <ul class="small-gap">
451 <li>PNaCl toolchain: <code>toolchain/&lt;platform&gt;_pnacl/usr/include</code></ li>
452 <li>x86 toolchains: <code>toolchain/&lt;platform&gt;_x86_&lt;library&gt;/x86_64- nacl/include</code></li>
453 <li>ARM toolchain: <code>toolchain/&lt;platform&gt;_arm_&lt;library&gt;/arm-nacl /include</code></li>
454 </ul>
455 <p>Many other libraries have been ported for use with Native Client; for more
456 information, see the <a class="reference external" href="http://code.google.com/ p/naclports/">naclports</a>
457 project. If you port an open-source library for your own use, we recommend
458 adding it to naclports.</p>
459 <p>Besides the standard libraries, the SDK includes Pepper libraries.
460 The PNaCl Pepper libraries are located in the the
461 <code>&lt;NACL_SDK_ROOT&gt;/lib/pnacl/&lt;Release or Debug&gt;</code> directory.
462 The GNU-based toolchain has Pepper libraries in
463 <code>&lt;NACL_SDK_ROOT&gt;/lib/newlib_&lt;arch&gt;/&lt;Release or Debug&gt;</co de>
464 and <code>&lt;NACL_SDK_ROOT&gt;/lib/glibc_&lt;arch&gt;/&lt;Release or Debug&gt;< /code>.
465 The libraries provided by the SDK allow the application to use Pepper,
466 as well as convenience libraries to simplify porting an application that
467 uses POSIX functions. Here are descriptions of the Pepper libraries provided
468 in the SDK.</p>
469 <dl class="docutils" id="devcycle-building-nacl-io">
470 <dt>libppapi.a</dt>
471 <dd>Implements the Pepper (PPAPI) C interface. Needed for all applications that
472 use Pepper (even C++ applications).</dd>
473 <dt>libppapi_cpp.a</dt>
474 <dd>Implements the Pepper (PPAPI) C++ interface. Needed by C++ applications that
475 use Pepper.</dd>
476 <dt>libppapi_gles2.a</dt>
477 <dd>Implements the Pepper (PPAPI) GLES interface. Needed by applications
478 that use the 3D graphics API.</dd>
479 <dt>libnacl_io.a</dt>
480 <dd>Provides a POSIX layer for NaCl. In particular, the library provides a
481 virtual file system and support for sockets. The virtual file system
482 allows a module to &#8220;mount&#8221; a given directory tree. Once a module has
483 mounted a file system, it can use standard C library file operations:
484 <code>fopen</code>, <code>fread</code>, <code>fwrite</code>, <code>fseek</code>, and <code>fclose</code>.
485 For more detail, see the header <code>include/nacl_io/nacl_io.h</code>.
486 For an example of how to use nacl_io, see <code>examples/demo/nacl_io</code>.</d d>
487 <dt>libppapi_simple.a</dt>
488 <dd>Provides a familiar C programming environment by letting a module have a
489 simple entry point that is registered by <code>PPAPI_SIMPLE_REGISTER_MAIN</code> .
490 The entry point is similar to the standard C <code>main()</code> function, compl ete
491 with <code>argc</code> and <code>argv[]</code> parameters. For details see
492 <code>include/ppapi_simple/ps.h</code>. For an example of
493 how to use ppapi_simple, <code>see examples/tutorial/using_ppapi_simple</code>.< /dd>
494 </dl>
495 <aside class="note">
496 <ul class="small-gap">
497 <li>Since the Native Client toolchains use their own library and header search
498 paths, the tools won&#8217;t find third-party libraries you use in your
499 non-Native-Client development. If you want to use a specific third-party
500 library for Native Client development, look for it in <a class="reference extern al" href="http://code.google.com/p/naclports/">naclports</a>, or port the librar y yourself.</li>
501 <li>The order in which you list libraries in your build commands is important,
502 since the linker searches and processes libraries in the order in which they
503 are specified. See the *_LDFLAGS variables in the Makefiles of the SDK
504 examples for the order in which specific libraries should be listed.</li>
505 </ul>
506
507 </aside>
508 </section><section id="troubleshooting">
509 <h2 id="troubleshooting">Troubleshooting</h2>
510 <p>Some common problems, and how to fix them:</p>
511 <section id="undefined-reference-error">
512 <h3 id="undefined-reference-error">&#8220;Undefined reference&#8221; error</h3>
513 <p>An &#8220;undefined reference&#8221; error may indicate incorrect link order and/or
514 missing libraries. For example, if you leave out <code>-lppapi</code> when
515 compiling Pepper applications you&#8217;ll see a series of undefined
516 reference errors.</p>
517 <p>One common type of &#8220;undefined reference&#8221; error is with respect to certain
518 system calls, e.g., &#8220;undefined reference to &#8216;mkdir&#8217;&#8221;. Fo r security reasons,
519 Native Client does not support a number of system calls. Depending on how
520 your code uses such system calls, you have a few options:</p>
521 <ol class="arabic simple">
522 <li>Link with the <code>-lnosys</code> flag to provide empty/always-fail version s of
523 unsupported system calls. This will at least get you past the link stage.</li>
524 <li>Find and remove use of the unsupported system calls.</li>
525 <li>Create your own implementation of the unsupported system calls to do
526 something useful for your application.</li>
527 </ol>
528 <p>If your code uses mkdir or other file system calls, you might find the
529 <a class="reference internal" href="#devcycle-building-nacl-io"><em>nacl_io</em> </a> library useful.
530 The nacl_io library essentially does option (3) for you: It lets your
531 code use POSIX-like file system calls, and implements the calls using
532 various technologies (e.g., HTML5 file system, read-only filesystems that
533 use URL loaders, or an in-memory filesystem).</p>
534 </section><section id="can-t-find-libraries-containing-necessary-symbols">
535 <h3 id="can-t-find-libraries-containing-necessary-symbols">Can&#8217;t find libr aries containing necessary symbols</h3>
536 <p>Here is one way to find the appropriate library for a given symbol:</p>
537 <pre>
538 &lt;NACL_SDK_ROOT&gt;/toolchain/&lt;platform&gt;_pnacl/bin/pnacl-nm -o \
539 toolchain/&lt;platform&gt;_pnacl/usr/lib/*.a | grep &lt;MySymbolName&gt;
540 </pre>
541 </section><section id="pnacl-abi-verification-errors">
542 <h3 id="pnacl-abi-verification-errors">PNaCl ABI Verification errors</h3>
543 <p>PNaCl has restrictions on what is supported in bitcode. There is a bitcode
544 ABI verifier which checks that the application conforms to the ABI restrictions,
545 before it is translated and run in the browser. However, it is best to
546 avoid runtime errors for users, so the verifier also runs on the developer&#8217 ;s
547 machine at link time.</p>
548 <p>For example, the following program which uses 128-bit integers
549 would compile with NaCl GCC for the x86-64 target. However, it is not
550 portable and would not compile with NaCl GCC for the i686 target.
551 With PNaCl, it would fail to pass the ABI verifier:</p>
552 <pre class="prettyprint">
553 typedef unsigned int uint128_t __attribute__((mode(TI)));
554
555 uint128_t foo(uint128_t x) {
556 return x;
557 }
558 </pre>
559 <p>With PNaCl you would get the following error at link time:</p>
560 <pre class="prettyprint">
561 Function foo has disallowed type: i128 (i128)
562 LLVM ERROR: PNaCl ABI verification failed
563 </pre>
564 <p>When faced with a PNaCl ABI verification error, check the list of features
565 that are <a class="reference internal" href="/native-client/nacl-and-pnacl.html# when-to-use-nacl"><em>not supported by PNaCl</em></a>.
566 If the problem you face is not listed as restricted,
567 <a class="reference internal" href="/native-client/help.html#help"><em>let us kn ow</em></a>!</p>
568 </section></section></section>
569
570 {{/partials.standard_nacl_article}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698