Every Native Client SDK bundle comes with a folder of example applications. Each example demonstrates one or two key Native Client programming concepts. After you've downloaded the SDK, follow the instructions on this page to build and run the examples.
Configure the Google Chrome Browser
- Your version of Chrome must be equal to or greater than the version of your SDK bundle. For example, if you're developing with the
pepper_31bundle, you must use Google Chrome version 31 or greater. To find out what version of Chrome you're using, type
about:versionin the Chrome address bar.
- Enable the Native Client flag. Native Client is enabled by default only for applications distributed through the Chrome Web
Store. To run Native Client applications that are not distributed through the Chrome Web Store, like the SDK examples, you must specifically enable the Native Client flag in Chrome:
about:flagsin the Chrome address bar and scroll down to "Native Client".
- If the link below "Native Client" says "Disable", then Native Client is already enabled and you don't need to do anything else.
- If the link below "Native Client" says "Enable", click the "Enable" link, scroll down to the bottom of the page, and click the "Relaunch Now" button. All browser windows will restart when you relaunch Chrome.
- Disable the Chrome cache. Chrome caches resources aggressively; when you are building a Native Client application you should disable the cache to make sure that Chrome loads the latest version:
- Open Chrome's developer tools by clicking the menu icon and choosing Tools > Developer tools.
- Click the gear icon in the bottom right corner of the Chrome window.
- Under the "General" settings, check the box next to "Disable cache".
Build the SDK examples
Starting with the
pepper_24 bundle, the Makefile scripts for the SDK examples build multiple versions of the examples using all three SDK toolchains (newlib, glibc, and PNaCl) and in both release and debug configurations. (Note that the debugging example builds only with the newlib toolchain, and the dlopen example only with glibc.)
To build all the examples, go to the examples directory in a specific SDK bundle and run
cd pepper_31/examples make
make from inside a particular example's directory will build only that example.
make, each example directory will contain the following subdirectories (with the two exceptions noted above ):
newlibdirectory with subdirectories
glibcdirectory with subdirectories
PNaCldirectory with subdirectories
For the newlib and glibc toolchains the Debug and Release subdirectories contain .nexe files for all target architectures. For the PNaCl toolchain they contain a single .pexe file. All Debug and Release directories contain a manifest (.nmf) file that references the associated .nexe or .pexe files. For information about Native Client manifest files, see the Technical Overview.
Start a local server
To protect against security vulnerabilities, you must load Native Client modules from a web server (either remote or local). Dragging and dropping Native Client HTML files into the browser address bar will not work. For more information, read about the Same Origin Policy, which protects the user's file system from outside access.
The Native Client SDK includes a Python web server that you can use to run applications that you build (including the SDK examples). The server is located in the tools directory. To start the web server, go to the examples directory in the SDK bundle that you are using and run the
httpd.py script. For example, if you are using the
pepper_31 bundle, run the following commands:
cd pepper_31/examples python ../tools/httpd.py
If you don't specify a port number, the server defaults to port 5103, and you can access the server at http://localhost:5103.
Run the SDK examples
Once you have started the local server, return to Chrome and point the browser at http://localhost:5103/ (be sure you specify the actual port number) and you'll see a page with a list of short descriptions and links to each SDK example. Click on a link to run the example.
The links on the SDK examples page launch one version of each example, usually the newlib/debug toolchain/configuration combination, however the make command builds a version of each example with every toolchain if possible. In an example's top level directory you'll find index pages that will launch every version created. The naming convention "index_<toolchain>_<configuration>.html" shows which build will be launched:
You can launch a particular toolchain/configuration combination by specifying the example's folder and a specific index page in Chrome. For instance, to launch the glibc debug version of hello_world, type: