After reading about Google’s Native Client (NaCl) for a while, I wanted to see how difficult it would be to share compiled code on the web, so I decided to dive into the docs and check it out.
I’ll start with the conclusion in case you aren’t really interested in the technical details (and since they are mostly just notes that will be outdated when NaCl updates anyway).
The problem I ran into is any code I would want to share is dependent on a set of libraries that I can only find in a .lib file (they are the libraries from CS106B), and I can’t seem to find a way to successfully link this library and use the functions from it.
I have a few different options like trying to set up the g++ compiler with Visual Studio (this has improved since writing, see update below) or rewriting the parts of the program with a standard set of libraries that I have access to (this would take a lot more time). Neither of those seem very appealing especially considering that I don’t have any major plans for using NaCl.
While I definitely find NaCl to be an interesting concept, I’ll be much more interested in playing around with it when it has an IDE (or plays nicer with existing ones) and up to date documentation.
Update
In the time since I drafted this post, two things have happened. First, NaCl is playing nicer with Visual Studio. Second, I’ve begun CS107. My plan is to return to this after I have some more interesting C code from CS107 and try out the VS integration.
The following are my notes from this project. Again, these will likely be outdated soon, but I ran into enough problems to share them so others might have an easier time.
Notes
Before I started developing, I had to enable NaCl in Chrome. You can do this by going to chrome://flags/, clicking enable Native Client, and restarting the browser.
Next, I went to the quick start guide which was straightforward: https://developers.google.com/native-client/quick-start
The main links are here to download and here to get started (though you may want to read on here before going through those).
After updating, Pepper 18 installed. There are two problems with this. First, the documentation is set by default to Pepper 16. Second, even the Pepper 18 documentation is outdated (more on this later).
On the download page, the last step tells you to set an environment variable. The instructions aren’t precise, but I’ve messed with environment variables before so this wasn’t too much trouble. However, I’m fairly certain with Pepper 18 this isn’t necessary, but see the next paragraph for how to do this if you were a little confused.
In Windows 7:
- type path into the start menu, go to edit system environment variables
- click on the Environment Variables button
- click ‘New’ under System variables
- set the name to %NACL_SDK_ROOT% and set the path to C:/nacl_sdk (or wherever you installed)
Why do I think this isn’t necessary? As of Pepper 18, NaCl uses make files instead of SCons (though there are still references to SCons and not make files in the docs). In the make file, they have a fail-safe if you don’t have the variable set.
I’m not sure if I missed a step somewhere or this is an artifact of the docs being outdated, but I was getting errors trying to run the examples on a local host in the tutorial, so I had to go to the console and execute ‘pepper18examplesmake.bat’. Now they seem to run fine.
Also a problem with the docs being outdated: for Step 5 of the tutorial, Pepper 18 no longer includes init_project.py. You should simply use the files from an example for your template.
These were the primary problems I ran into with the documentation.
I used the hello_world_interactive example as my template and started editing the ‘helper_functions.cc’ file. To get things to show up, simply edit the code, save, run make.bat in the directory, then rehost (I was using the simple Python local host recommended in the docs). Simple enough and I had a live NaCl app running.