Outdated Docs > Native Client Environment Setup

Native Client Environment Setup

Native Client (NaCl) is a secure native code runtime for the web that is part of the Chrome (and chromium) browser. For general information
on developing for NaCl see the main developer docs here:


If you are running a recent chromium-based browser you can see cocos2dx on NaCl in action by installing the test application from the chrome webstore:


Also Marmalade’s OpenQuick example application running on cocos2dx is in the webstore here

Applications built with cocos2dx require Chrome version 25 and above. In order to run NaCl applications during development you will need to enable NaCl in your browser. You can do this by enabling Native Client in the on the chrome://flags page, or by launching chrome with —enable-nacl.

To cocos2dx port for NaCl currently requires a Linux development environment. It also requires the very latest version of the NaCl SDK known as pepper_canary. One you have installed the NaCl SDK updater you can install/update pepper_canary using the following command:

$ ./naclsdk update --force pepper_canary

Next you need to set the NACL_SDK_ROOT to point to the pepper_canary folder and add the compiler binaries to your PATH:

$ export NACL_SDK_ROOT=/path/to/naclsdk/pepper_canary
$ export PATH=$PATH:$NACL_SDK_ROOT/toolchain/linux_x86_newlib/bin:$NACL_SDK_ROOT/toolchain/linux_arm_newlib/bin


The build system for cocos2dx on NaCl is very similar to the build system for Linux. The best place to start is to run to ‘build-nacl.sh’ script from the top level cocos2dx directory. This will build all the cocos2dx components and examples for all three NaCl architectures: x86_64, i686, and arm.

$ ./build-nacl.sh

All this script does is invoke ‘make’ several times with different arguments. During development you most likely only want to build one configuration at time by running ‘make’ directly. e.g:

$ make -j5 PLATFORM=nacl DEBUG=1 NACL_ARCH=x86_64

This will build all cocos2dx libraries and examples in x86_64 debug mode. Libraries are build into the ‘lib/nacl/x86_64/Debug’ folder.

If you just want to build a single library or a single example just run make from the proj.nacl folder for that library or example. e.g:

$ cd samples/Cpp/TestCpp/proj.nacl && make -j5 DEBUG=1 NACL_ARCH=x86_64

Remember to add the j argument when you run make to dramatically speed up your build time.
h2. Running
The makefiles provides include a ‘run’ target which can be used to publish your application in a local webserver. e.g.:
\$ cd samples/Cpp/TestCpp/proj.nacl && make
j5 DEBUG=1 NACL_ARCH=x86_64 run

Once this is running you can browse to the application in chrome at http://localhost:5103/

Packaging for the Chrome WebStore

The TestCpp sample includes a make rules for packaging an app for the Chrome WebStore. You can run ‘make package’ to create a chrome app folder containing your app and ‘make zip’ to zip it up into a WebStore package.

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.