Native Client

Running the SDK Examples

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

  1. 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_31 bundle, you must use Google Chrome version 31 or greater. To find out what version of Chrome you're using, type about:chrome or about:version in the Chrome address bar.
  2. 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:
    • Type about:flags in 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.
  3. 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 menu icon and choosing Tools > Developer tools.
    • Click the gear icon 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 make:

cd pepper_31/examples
make

Calling make from inside a particular example's directory will build only that example.

After running make, each example directory will contain the following subdirectories (with the two exceptions noted above ):

  • a newlib directory with subdirectories Debug and Release;
  • a glibc directory with subdirectories Debug and Release;
  • a PNaCl directory with subdirectories Debug and Release;

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.

For details on how to use make, see the GNU 'make' Manual. For details on how to use the SDK toolchain itself, see Building Native Client Modules.

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:

  • index_glibc_Debug.html
  • index_glibc_Release.html
  • index_newlib_Debug.html
  • index_newlib_Release.html
  • index_pnacl_Debug.html
  • index_pnacl_Release.html

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:

http://localhost:5103/hello_world/index_glibc_Debug.html 

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.