OLD | NEW |
(Empty) | |
| 1 .. _sdk-examples-2: |
| 2 |
| 3 Running the SDK Examples |
| 4 ======================== |
| 5 |
| 6 Every Native Client SDK bundle comes with a folder of example applications. |
| 7 Each example demonstrates one or two key Native Client programming concepts. |
| 8 After you've :doc:`downloaded the SDK <download>`, follow the instructions |
| 9 on this page to build and run the examples. |
| 10 |
| 11 Configure the Google Chrome Browser |
| 12 ----------------------------------- |
| 13 |
| 14 1. Your version of Chrome must be equal to or greater than the version of |
| 15 your SDK bundle. For example, if you're developing with the ``pepper_28`` |
| 16 bundle, you must use Google Chrome version 28 or greater. To find out what |
| 17 version of Chrome you're using, type ``about:chrome`` or ``about:version`` |
| 18 in the Chrome address bar. |
| 19 |
| 20 2. Enable the Native Client flag. Native Client is enabled by default only |
| 21 for applications distributed through the Chrome Web Store. To run Native |
| 22 Client applications that are not distributed through the Chrome Web Store, |
| 23 like the SDK examples, you must specifically enable the Native Client flag |
| 24 in Chrome: |
| 25 |
| 26 * Type ``about:flags`` in the Chrome address bar and scroll down to |
| 27 "Native Client". |
| 28 * If the link below "Native Client" says "Disable", then Native Client is |
| 29 already enabled and you don't need to do anything else. |
| 30 * If the link below "Native Client" says "Enable", click the "Enable" |
| 31 link, scroll down to the bottom of the page, and click the "Relaunch |
| 32 Now" button. All browser windows will restart when you relaunch Chrome. |
| 33 |
| 34 3. Disable the Chrome cache. Chrome caches resources aggressively; when you |
| 35 are building a Native Client application you should disable the cache to |
| 36 make sure that Chrome loads the latest version: |
| 37 |
| 38 * Open Chrome's developer tools by clicking the menu icon |menu-icon| and |
| 39 choosing Tools > Developer tools. |
| 40 * Click the gear icon |gear-icon| in the bottom right corner of the |
| 41 Chrome window. |
| 42 * Under the "General" settings, check the box next to "Disable cache". |
| 43 |
| 44 Build the SDK examples |
| 45 ---------------------- |
| 46 |
| 47 Starting with the ``pepper_24`` bundle, the Makefile scripts for the SDK |
| 48 examples build multiple versions of the examples using all three SDK |
| 49 toolchains (newlib, glibc, and PNaCl) and in both release and debug |
| 50 configurations. (Note that some examples build only with the particular |
| 51 toolchains). |
| 52 |
| 53 To build all the examples, go to the examples directory in a specific SDK |
| 54 bundle and run ``make``:: |
| 55 |
| 56 $ cd pepper_28/examples |
| 57 $ make |
| 58 make -C api all |
| 59 make[1]: Entering directory `pepper_28/examples/api' |
| 60 make -C audio all |
| 61 make[2]: Entering directory `pepper_28/examples/api/audio' |
| 62 CXX newlib/Debug/audio_x86_32.o |
| 63 LINK newlib/Debug/audio_x86_32.nexe |
| 64 CXX newlib/Debug/audio_x86_64.o |
| 65 LINK newlib/Debug/audio_x86_64.nexe |
| 66 CXX newlib/Debug/audio_arm.o |
| 67 LINK newlib/Debug/audio_arm.nexe |
| 68 CREATE_NMF newlib/Debug/audio.nmf |
| 69 make[2]: Leaving directory `pepper_28/examples/api/audio' |
| 70 make -C url_loader all |
| 71 make[2]: Entering directory `pepper_28/examples/api/url_loader' |
| 72 CXX newlib/Debug/url_loader_x86_32.o |
| 73 ... |
| 74 |
| 75 Calling ``make`` from inside a particular example's directory will build only |
| 76 that example:: |
| 77 |
| 78 $ cd pepper_28/examples/api/core |
| 79 $ make |
| 80 CXX newlib/Debug/core_x86_32.o |
| 81 LINK newlib/Debug/core_x86_32.nexe |
| 82 CXX newlib/Debug/core_x86_64.o |
| 83 LINK newlib/Debug/core_x86_64.nexe |
| 84 CXX newlib/Debug/core_arm.o |
| 85 LINK newlib/Debug/core_arm.nexe |
| 86 CREATE_NMF newlib/Debug/core.nmf |
| 87 |
| 88 You can call ``make`` with the ``TOOLCHAIN`` and ``CONFIG`` parameters to |
| 89 override the defaults:: |
| 90 |
| 91 $ make TOOLCHAIN=pnacl CONFIG=Release |
| 92 CXX pnacl/Release/core_pnacl.o |
| 93 LINK pnacl/Release/core.bc |
| 94 FINALIZE pnacl/Release/core.pexe |
| 95 CREATE_NMF pnacl/Release/core.nmf |
| 96 |
| 97 |
| 98 You can also set ``TOOLCHAIN`` to "all" to build one or more examples with |
| 99 all available toolchains:: |
| 100 |
| 101 $ make TOOLCHAIN=all |
| 102 make TOOLCHAIN=newlib |
| 103 make[1]: Entering directory `pepper_31/examples/api/core' |
| 104 CXX newlib/Debug/core_x86_32.o |
| 105 LINK newlib/Debug/core_x86_32.nexe |
| 106 CXX newlib/Debug/core_x86_64.o |
| 107 LINK newlib/Debug/core_x86_64.nexe |
| 108 CXX newlib/Debug/core_arm.o |
| 109 LINK newlib/Debug/core_arm.nexe |
| 110 CREATE_NMF newlib/Debug/core.nmf |
| 111 make[1]: Leaving directory `pepper_31/examples/api/core' |
| 112 make TOOLCHAIN=glibc |
| 113 make[1]: Entering directory `pepper_31/examples/api/core' |
| 114 CXX glibc/Debug/core_x86_32.o |
| 115 LINK glibc/Debug/core_x86_32.nexe |
| 116 CXX glibc/Debug/core_x86_64.o |
| 117 LINK glibc/Debug/core_x86_64.nexe |
| 118 CREATE_NMF glibc/Debug/core.nmf |
| 119 make[1]: Leaving directory `pepper_31/examples/api/core' |
| 120 make TOOLCHAIN=pnacl |
| 121 make[1]: Entering directory `pepper_31/examples/api/core' |
| 122 CXX pnacl/Debug/core_pnacl.o |
| 123 LINK pnacl/Debug/core.bc |
| 124 FINALIZE pnacl/Debug/core.pexe |
| 125 TRANSLATE pnacl/Debug/core_x86_32.nexe |
| 126 TRANSLATE pnacl/Debug/core_x86_64.nexe |
| 127 TRANSLATE pnacl/Debug/core_arm.nexe |
| 128 CREATE_NMF pnacl/Debug/core.nmf |
| 129 make[1]: Leaving directory `pepper_31/examples/api/core' |
| 130 make TOOLCHAIN=linux |
| 131 make[1]: Entering directory `pepper_31/examples/api/core' |
| 132 CXX linux/Debug/core.o |
| 133 LINK linux/Debug/core.so |
| 134 make[1]: Leaving directory `pepper_31/examples/api/core' |
| 135 |
| 136 |
| 137 After running ``make``, each example directory will contain one or more of |
| 138 the following subdirectories: |
| 139 |
| 140 * a ``newlib`` directory with subdirectories ``Debug`` and ``Release``; |
| 141 * a ``glibc`` directory with subdirectories ``Debug`` and ``Release``; |
| 142 * a ``pnacl`` directory with subdirectories ``Debug`` and ``Release``; |
| 143 |
| 144 For the newlib and glibc toolchains the Debug and Release subdirectories |
| 145 contain .nexe files for all target architectures. For the PNaCl toolchain |
| 146 they contain a single .pexe file. PNaCl debug also produces pre-translated |
| 147 .nexe files, for ease of debugging. All Debug and Release directories contain |
| 148 a manifest (.nmf) file that references the associated .nexe or .pexe files. |
| 149 For information about Native Client manifest files, see the :doc:`Technical |
| 150 Overview <../overview>`. |
| 151 |
| 152 For details on how to use ``make``, see the `GNU 'make' Manual |
| 153 <http://www.gnu.org/software/make/manual/make.html>`_. For details on how to |
| 154 use the SDK toolchain itself, see :doc:`Building Native Client Modules |
| 155 <devcycle/building>`. |
| 156 |
| 157 Run the SDK examples |
| 158 -------------------- |
| 159 |
| 160 To run the SDK examples, you can use the ``make run`` command:: |
| 161 |
| 162 $ cd pepper_28/examples/api/core |
| 163 $ make run |
| 164 |
| 165 This will launch a local HTTP server which will serve the data for the |
| 166 example. It then launches Chrome with the address of this server, usually |
| 167 http://localhost:5103. After you close Chrome, the local HTTP server is |
| 168 automatically shutdown. |
| 169 |
| 170 This command will try to find an executable named ``google-chrome`` in your |
| 171 ``PATH`` environment variable. If it can't, you'll get an error message like |
| 172 this:: |
| 173 |
| 174 pepper_31/tools/common.mk:415: No valid Chrome found at CHROME_PATH= |
| 175 pepper_31/tools/common.mk:415: *** Set CHROME_PATH via an environment variab
le, or command-line.. Stop. |
| 176 |
| 177 Set the CHROME_PATH environment variable to the location of your Chrome |
| 178 executable **TODO(binji):** use default Chrome paths here, especially |
| 179 important for Mac: |
| 180 |
| 181 On Windows:: |
| 182 |
| 183 > set CHROME_PATH=<Path to chrome.exe> |
| 184 |
| 185 On Linux:: |
| 186 |
| 187 $ export CHROME_PATH=<Path to google-chrome> |
| 188 |
| 189 On Mac:: |
| 190 |
| 191 $ export CHROME_PATH=<Path to chrome> |
| 192 |
| 193 |
| 194 You can run via a different toolchain or configuration by using the |
| 195 ``TOOLCHAIN`` and ``CONFIG`` parameters to make:: |
| 196 |
| 197 $ make run TOOLCHAIN=pnacl CONFIG=Debug |
| 198 |
| 199 |
| 200 Run the SDK examples as packaged apps |
| 201 ------------------------------------- |
| 202 |
| 203 Each example can also be launched as a packaged app. For more information about |
| 204 using Native Client for packaged apps, see :ref:`Packaged appliction |
| 205 <packaged>`. For general information about packaged apps, see the |
| 206 `Chrome apps documentation |
| 207 <http://developer.chrome.com/apps/about_apps.html>`_. |
| 208 |
| 209 Some Pepper features, such as TCP/UDP socket access, are only allowed in |
| 210 packaged apps. The examples that use these features must be run as packaged |
| 211 apps, by using the ``make run_package`` command:: |
| 212 |
| 213 $ make run_package |
| 214 |
| 215 You can use ``TOOLCHAIN`` and ``CONFIG`` parameters as above to run with a |
| 216 different toolchain or configuration. |
| 217 |
| 218 Debugging the SDK examples |
| 219 -------------------------- |
| 220 |
| 221 The NaCl SDK uses `GDB <https://www.gnu.org/software/gdb/>`_ to debug Native |
| 222 Client code. The SDK includes a prebuilt version of GDB that is compatible with |
| 223 NaCl code. To use it, run the ``make debug`` command from an example directory:: |
| 224 |
| 225 $ make debug |
| 226 |
| 227 This will launch Chrome with the ``--enable-nacl-debug`` flag set. This flag |
| 228 will cause Chrome to pause when a NaCl module is first loaded, waiting for a |
| 229 connection from gdb. The ``make debug`` command also simultaneously launches |
| 230 GDB and loads the symbols for that NEXE. To connect GDB to Chrome, in the GDB |
| 231 console, type:: |
| 232 |
| 233 (gdb) target remote :4014 |
| 234 |
| 235 This tells GDB to connect to a TCP port on localhost:4014--the port that |
| 236 Chrome is listening on. GDB will respond:: |
| 237 |
| 238 Remote debugging using :4014 |
| 239 0x000000000fa00080 in ?? () |
| 240 |
| 241 At this point, you can use the standard GDB commands to debug your NaCl module. |
| 242 The most common commands you will use to debug are ``continue``, ``step``, |
| 243 ``next``, ``break`` and ``backtrace``. See :doc:`Debugging |
| 244 <devcycle/debugging>` for more information about debugging a Native Client |
| 245 application. |
| 246 |
| 247 |
| 248 .. |menu-icon| image:: /images/menu-icon.png |
| 249 .. |gear-icon| image:: /images/gear-icon.png |
OLD | NEW |