std classes support
Hello! I can't understand if it is possible to include std libraries as "map", "vector", "string" with your "wscript". I've added:
include
include
to my code and it has been compiled successfully, but I got bunch of errors during linking:
src/tracker.cpp.10.o: In function
std::vector<BaseTracking*, std::allocator<BaseTracking*> >::_M_range_check(unsigned int) const': tracker.cpp:(.text._ZNKSt6vectorIP12BaseTrackingSaIS1_EE14_M_range_checkEj[_ZNKSt6vectorIP12BaseTrackingSaIS1_EE14_M_range_checkEj]+0x48): undefined reference tostd::throw_out_of_range(char const)' src/tracker.cpp.10.o: In function `std::Rb_tree_iterator<std::pair<char const, char> > std::Rb_tree<char, std::pair<char* const, char*>, std::_Select1st<std::pair<char* const, char*> >, std::less<char*>, std::allocator<std::pair<char* const, char*> > >::M_insert<std::pair<char* const, char*> const&>(std::Rb_tree_node_base const, std::Rb_tree_node_base const, std::pair<char* const, char*> const&)':Build failed -> task in 'basalt/pebble-app.elf' failed (exit status 1): {task 4452181008: cprogram tracker.cpp.10.o,tracker_data.cpp.10.o,appinfo.auto.c.10.o,resource_ids.auto.c.10.o -> pebble-app.elf} ['arm-none-eabi-gcc', '-mcpu=cortex-m3', '-mthumb', '-Wl,--gc-sections', '-Wl,--warn-common', '-fPIE', '-Os', '-Wl,--build-id=sha1', '-Wl,-Map,pebble-app.map,--emit-relocs', '-T/Users/strannik/Looksery/projects/pebble_tracker/build/basalt/pebble_app.ld.auto', 'src/tracker.cpp.10.o', 'src/tracker_data.cpp.10.o', 'basalt/appinfo.auto.c.10.o', 'basalt/src/resource_ids.auto.c.10.o', '-o', '/Users/strannik/Looksery/projects/pebble_tracker/build/basalt/pebble-app.elf', '-L/Users/strannik/Library/Application Support/Pebble SDK/SDKs/current/sdk-core/pebble/basalt/lib', '-lpebble']
Am I do something wrong?
I'd be surprised if they work, even if you got it to compile. The watches don't have much memory, so if you start using std::vector and friends, you're going to run out of heap pretty quickly. I made new and free work by just calling malloc and delete, but that doesn't mean you should do too much heap allocation.
I think std::array and std::unique_ptr would be good to have working, but not std::vector. Do those work for you?
I use very small vector. 6 elements at maximum. But vector is convenient since it gives functions for easy insert/remove. Moreover, I use small map for the same reason.
But I've found that problem is more general. I can't start any application by your wscript, even standard "Hello, pebble!". I can build application and even install, but nothing happens after installation...
I use 3.13.1 SDK, basalt emulator. That is my code:
extern "C" {
#include <pebble.h>
}
Window *window;
TextLayer *text_layer;
void init() {
window = window_create();
text_layer = text_layer_create(GRect(0, 0, 144, 40));
text_layer_set_text(text_layer, "Hello!");
layer_add_child(window_get_root_layer(window),
text_layer_get_layer(text_layer));
window_stack_push(window, true);
}
void deinit() {
text_layer_destroy(text_layer);
window_destroy(window);
}
int main() {
init();
app_event_loop();
deinit();
return 0;
}
The only change is "extern "C"" wrapper, nothing more. No cpp syntax or calls.
What does it do? If you're logging hello world, it will only log that to the development console and then exit, you won't see anything on the watch. On Jun 14, 2016 10:33 AM, "Sergey Kotsur" [email protected] wrote:
I use very small vector. 6 elements at maximum. But vector is convenient since it gives functions for easy insert/remove. Moreover, I use small map for the same reason.
But I've found that problem is more general. I can't start any application by your wscript, even standard "Hello, pebble!". I can build application and even install, but nothing happens after installation...
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fahhem/pebble-cpp/issues/2#issuecomment-225956235, or mute the thread https://github.com/notifications/unsubscribe/AASrtCK9m3yOaqeCyYSpY8A7hy0c1EKNks5qLuXVgaJpZM4Iy7fD .
To make it clear. It doesn't work even in this case: pebble_hello_world.cpp:
extern "C" {
#include <pebble.h>
}
extern "C" int main(void) {
Window* window = window_create();
window_stack_push(window, true);
app_event_loop();
window_destroy(window);
return 0;
}
package.json:
{
"name": "example-app",
"author": "MakeAwesomeHappen",
"version": "1.0.0",
"keywords": ["pebble-app"],
"private": true,
"dependencies": {},
"pebble": {
"displayName": "example-app",
"uuid": "90C232E4-F983-4767-83ED-E761134F11B0",
"sdkVersion": "3",
"targetPlatforms": [
"basalt"
],
"watchapp": {
"watchface": false
},
"messageKeys": [
"dummy"
],
"resources": {
"media": []
}
}
}
wscript:
import os.path
top = '.'
out = 'build'
def options(ctx):
ctx.load('pebble_sdk')
ctx.load('g++')
def configure(ctx):
ctx.load('pebble_sdk')
CROSS_COMPILE_PREFIX = 'arm-none-eabi-'
ctx.env.CXX = CROSS_COMPILE_PREFIX+'g++'
ctx.load('g++')
ctx.env.CXXFLAGS = list(ctx.env.CFLAGS)
sdk_folder = ctx.root.find_dir(ctx.env['PEBBLE_SDK'])
ctx.env.CXXFLAGS.extend(['-std=c++11', '-fPIE', '-fno-unwind-tables', '-fno-exceptions'])
def build(ctx):
ctx.load('pebble_sdk')
binaries = []
for p in ctx.env.TARGET_PLATFORMS:
ctx.set_env(ctx.all_envs[p])
app_elf='{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.cpp'),
target=app_elf)
binaries.append({'platform': p, 'app_elf': app_elf})
ctx.pbl_bundle(binaries=binaries)
"pebble logs" error on launch (by select button) in basalt emulator:
>> pebble logs
[13:06:21] ault_handling.c:93> App fault! {90c232e4-f983-4767-83ed-e761134f11b0} PC: 0xaa LR: 0x80079ed
Program Counter (PC) : 0xaa ??:?
Link Register (LR) : 0x80079ed ???
And it works well if I've just changed:
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.cpp')
by
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c')
changed ".cpp" extension by ".c" and removed "extern "C"" wrappers. I suppose that something is wrong in your wscript. Probably something has been changed after Pebble SDK update...
BTW: I am working on OS X.
I did it! You need to change:
ctx.env.CXXFLAGS.extend(['-std=c++11', '-fPIE', '-fno-unwind-tables', '-fno-exceptions'])
by
ctx.env.CXXFLAGS.extend(['-std=c++11', '-fPIE', '-fno-unwind-tables', '-fno-exceptions', '-mthumb'])
And it works!