c - Error in CloudPebble, "ld returned 1 exit status" -


so, i'm trying make pebble app generates random string when press button. i'm pretty sure have pebble code right, i'm not sure error:

/sdk2/[long stuff here]/ in function `_sbrk_r': /home/[more long stuff]: undefined reference `_sbrk' collect2: error: ld returned 1 exit status waf: leaving directory `/tmp/tmpx94xy7/build' build failed 

and here's code:

#include <pebble.h> #include <stdlib.h> #include <stdio.h>  window *window; textlayer *text_layer;  char* one[] = {"string1", "stringone", "stringuno"}; char* two[] = {"string2", "stringtwo", "stringdos"}; char* three[] = {"string3", "stringthree", "stringtres"}; char* four[] = {"string4", "stringfour", "stringcuatro"};  int length1 = sizeof(one)/sizeof(*one); int length2 = sizeof(two)/sizeof(*two); int length3 = sizeof(three)/sizeof(*three); int length4 = sizeof(four)/sizeof(*four);  char* gen() {     char out[256];     sprintf(out, "%s, , %s %s %s.", one[rand() % length1], two[rand() % length2], three[rand() % length3], four[rand() % length4]);      char* result = malloc(strlen(out) + 1);     strcpy(result, out);     return result; }  static void select_click_handler(clickrecognizerref recognizer, void *context) {     char* stringgen = gen();     text_layer_set_text(text_layer, stringgen);     free(stringgen); }  static void click_config_provider(void *context) {     window_single_click_subscribe(button_id_select, select_click_handler);     window_single_click_subscribe(button_id_up, select_click_handler);     window_single_click_subscribe(button_id_down, select_click_handler); }  static void window_load(window *window) {     layer *window_layer = window_get_root_layer(window);     grect bounds = layer_get_bounds(window_layer);      text_layer = text_layer_create((grect) { .origin = { 0, 72 }, .size = { bounds.size.w, bounds.size.h } });     text_layer_set_text(text_layer, "press >>>");      text_layer_set_text_alignment(text_layer, gtextalignmentcenter);     layer_add_child(window_layer, text_layer_get_layer(text_layer)); }  static void window_unload(window *window) {     text_layer_destroy(text_layer); }  void handle_init(void) {     window = window_create();     window_set_click_config_provider(window, click_config_provider);     window_set_window_handlers(window, (windowhandlers) {         .load = window_load,         .unload = window_unload,     });     const bool animated = true;     window_stack_push(window, animated);     }  void handle_deinit(void) {       text_layer_destroy(text_layer);       window_destroy(window); }  int main(void) {     handle_init();     app_event_loop();     handle_deinit(); } 

i can't figure out why i'm getting error. it's simple application, have these little tweaks.

thank in advance help!

according this (old) faq, error happens when try use c standard library function hasn't been implemented in sdk. if in the api reference, snprintf available, not sprintf. can replace call sprintf in gen like

snprintf(out, 256, "%s, , %s %s %s.", one[rand() % length1], two[rand() % length2], three[rand() % length3], four[rand() % length4]); 

i tried out , builds fine.

(as aside, may better idea declare out global static buffer , write on each time, instead of dynamically allocating memory.)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -