Google’s Native Client (NaCl) is a browser technology that allows you to run compiled C/C++ directly in the browser in a secure way. NaCl is cross platform and runs on multiple architectures. I’ll here give a short introduction to how to setup to use the NaCl-toolchain in NetBeans. I use OS/X, but I believe that the method described also works on Linux and Windows.
Setup NaCL project
This tutorial is created based on the ‘Gettings started‘-tutorial on the Native Client SDK webpage.
The first step, is to setup the NaCl on your computer (copied from the tutorial):
- Download the Native Client SDK and complete the following steps:
- Be sure you have a version of the Google Chrome browser that supports Native Client (version 10 or later). Install a new version of Google Chrome if necessary.
- In addition, enable Native Client in Chrome by typing about:flags into the browser’s address bar and then click “Enable” under Native Client. Restart the browser (scroll down to the bottom of the page and click the Restart button).
- On Mac or Linux systems, make sure you have Python installed.
- Start the simple Python web server that is included in the SDK (in the examples/ directory) with the command python httpd.py 5103. This runs the sample server at the following URL: http://localhost:5103.
Now you need to create a project. We’ll create the project in the example directory, since this allows you easily test your application (NaCl requires that the executable is recieved from a webserver).
Navigate to the directory project_templates/ and run the command following command to create the project hello_nb_cc:
python init_project.py -d ../examples -n hello_nb_cc
Install NetBeans IDE C/C++ 7.0 (currently in beta).
To setup the toolchain open the preferences and select C/C++ -> Build tools click ‘Add…’. In the ‘Add New Tool Collection’ dialog set the Base Directory to ‘(installdir)/toolchain/mac_x86/bin’, set tool collection family to GNU and name it GNU_Native_Client:
Now set the following directories:
- Base Directory: (installdir)/toolchain/mac_x86/bin
- C Compiler: (installdir)/toolchain/mac_x86/bin/nacl-gcc
- C++ Compiler: (installdir)/toolchain/mac_x86/bin/nacl-c++
- Assembler: (installdir)/toolchain/mac_x86/bin/nacl-as
Click OK to finish setting up the toolchain.
Choose C/C++ -> C/C++ Project with Existing Sources. In the next dialog select the directory examples/hello_nb_cc, set the Tool Collection to GLU_Native_Client and choose automatic or custom configuration.
You don’t need to change anything else in the project creation, so click Next until NetBeans allows you to click Finish.
You have now installed the project. Click Build in NetBeans to compile the project and verify that it works by open http://localhost:5103/hello_nb_cc/hello_nb_cc.html in Chrome. If the project is compiled succesfully you should see the following in the Chrome browser:
You can now do step 4-7 from the ‘Gettings started‘-tutorial to make the hello_nb_cc a little bit more meaningful.