Pebble Foundation Classes
0.2.0
C++ for Pebble
|
Use the following steps to create a new C++ application from scratch. In this short tutorial we will create a simple application that tells the time and responds to clicks.
From the command line start a new project as usual:
Then use the pebble package install
command to install the pebble-cpp
package. Execute a pebble build
to initialize the package.
The wscript
file located in the project root contains the instructions for the Pebble build system to compile the source files. This file needs to be modified to add commands to build C++ *.cpp
files.
You can copy an updated version of this file from the package folder node_modules/pebble-cpp/dist/include/pebble-cpp/wscript
. Execute the following command in the root of your project to copy this file over the existing wscript
file.
Alternatively you can view and download the updated wscript
file from here.
We've now added the ability to build C++ files but we haven't changed the ability to build C files. In fact, you can freely mix C and C++ files. But for the purposes of this tutorial we will erase the default C file and create a new single-file C++ application:
Remove the existing source file:
And now in your favorite text editor, create a new file called helloworld.cpp
in the src/c
folder. In that file add the following contents:
With all that code in the helloworld.cpp
file we just need to build the project and run it in the emulator:
If you have problems with the build, check the Known Issues.