CloudPebble中的错误,“;ld返回1退出状态“;

CloudPebble中的错误,“;ld返回1退出状态“;,c,pebble-watch,cloudpebble,C,Pebble Watch,Cloudpebble,所以,我尝试制作一个Pebble应用程序,当你按下一个按钮时,它会生成一个随机字符串。我很确定我的Pebble代码是正确的,但我不确定如何处理此错误: /sdk2/[long stuff here]/ In function `_sbrk_r': /home/[more long stuff]: undefined reference to `_sbrk' collect2: error: ld returned 1 exit status Waf: Leaving directory `/tm

所以,我尝试制作一个Pebble应用程序,当你按下一个按钮时,它会生成一个随机字符串。我很确定我的Pebble代码是正确的,但我不确定如何处理此错误:

/sdk2/[long stuff here]/ In function `_sbrk_r':
/home/[more long stuff]: undefined reference to `_sbrk'
collect2: error: ld returned 1 exit status
Waf: Leaving directory `/tmp/tmpX94xY7/build'
Build failed
这是我的代码:

#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, and then %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();
}
#包括
#包括
#包括
窗口*窗口;
文本层*文本层;
char*one[]={“string1”、“stringone”、“stringuno”};
char*two[]={“string2”、“stringtwo”、“stringdos”};
char*three[]={“string3”、“stringthree”、“stringtres”};
char*four[]={“string4”、“stringfour”、“stringcuatro”};
int length1=sizeof(一)/sizeof(*一);
int length2=sizeof(二)/sizeof(*二);
int length3=尺寸(三)/尺寸(*三);
int length4=四个尺寸/四个尺寸(*4);
char*gen()
{
字符输出[256];
sprintf(out,“%s,然后是%s%s%s.”,一个[rand()%length1],两个[rand()%length2],三个[rand()%length3],四个[rand()%length4]);
char*result=malloc(strlen(out)+1);
strcpy(结果,输出);
返回结果;
}
静态无效选择\单击\处理程序(单击识别器参考识别器,无效*上下文)
{
char*stringGen=gen();
文本层设置文本(文本层,stringGen);
免费(stringGen);
}
静态无效单击配置提供程序(无效*上下文)
{
窗口\单击\订阅(按钮\ ID \选择,选择\单击\处理程序);
窗口单击订阅(按钮ID向上,选择单击处理程序);
窗口单击订阅(按钮ID向下,选择单击处理程序);
}
静态空心窗荷载(窗*窗)
{
图层*窗口\图层=窗口\获取\根\图层(窗口);
GRect bounds=层\获取\边界(窗口\层);
text_layer=text_layer_create((GRect){.origin={0,72},.size={bounds.size.w,bounds.size.h});
文本层设置文本(文本层,“按>>>”);
文本层设置文本对齐(文本层,GTextAlignmentCenter);
层添加子层(窗口层、文本层、获取层(文本层));
}
静态无效窗口\卸载(窗口*窗口)
{
文本层销毁(文本层);
}
void handle_init(void)
{
window=window_create();
窗口\设置\单击\配置\提供程序(窗口,单击\配置\提供程序);
窗口\设置\窗口\处理程序(窗口,(窗口处理程序){
.荷载=窗荷载,
.unload=window\u unload,
});
const bool animated=true;
窗口\堆栈\推送(窗口,动画);
}
无效句柄\u去离子剂(无效)
{
文本层销毁(文本层);
窗口破坏(窗口);
}
内部主(空)
{
handle_init();
app_event_loop();
handle_deinit();
}
我不明白为什么我会犯这样的错误。这是一个简单的应用程序,我只是有这些小调整

提前感谢您的帮助

根据,当您尝试使用尚未在SDK中实现的C标准库函数时,会发生该错误。如果您查看,
snprintf
是可用的,但不是
sprintf
。您可以将对
gen
中的
sprintf
的调用替换为

snprintf(out, 256, "%s, and then %s %s %s.", one[rand() % length1], two[rand() % length2], three[rand() % length3], four[rand() % length4]);
我刚刚试过这个,它可以很好地构建

(顺便说一句,最好声明
out
一个全局静态缓冲区,每次只写一次,而不是不断地动态分配内存。)