0

这些错误是什么意思?在生成 Kaa SDK 并运行它之后,我正在遵循指南,但我遇到了这些错误。

 /home/pi/labsdk-RP/client/c/src/kaa_demo.c: In function ‘main’:
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:145:5: error: parameter ‘ret’ is initialized
         int ret = target_initialize();
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:146:5: error: expected declaration specifiers before ‘if’
         if (ret < 0) {
         ^
    In file included from /home/pi/labsdk-RP/client/c/src/kaa_demo.c:20:0:
    /home/pi/labsdk-RP/client/c/targets/posix/target.h:34:31: error: expected declaration specifiers before ‘printf’
     #define demo_printf(msg, ...) printf((msg), ##__VA_ARGS__)
                                   ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:152:5: note: in expansion of macro ‘demo_printf’
         demo_printf("Data collection demo started\r\n");
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:157:5: error: parameter ‘kaa_client’ is initialized
         kaa_client_t *kaa_client = NULL;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:158:5: error: parameter ‘error’ is initialized
         kaa_error_t error = kaa_client_create(&kaa_client, NULL);
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:160:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:166:5: error: expected declaration specifiers before ‘sensor_context’
         sensor_context.kaa_client = kaa_client;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:167:5: error: parameter ‘receiver’ is initialized
         kaa_configuration_root_receiver_t receiver = {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:172:5: error: expected declaration specifiers before ‘error’
         error = kaa_configuration_manager_set_root_receiver(
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:176:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:181:5: error: parameter ‘default_configuration’ is initialized
         const kaa_configuration_empty_data_t *default_configuration =
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:184:5: error: expected declaration specifiers before ‘sensor_context’
         sensor_context.sample_period = default_configuration->sample_period;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:185:5: error: expected declaration specifiers before ‘sensor_context’
         sensor_context.last_upload_time = time(NULL);
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:187:5: error: parameter ‘log_upload_strategy_context’ is initialized
         void *log_upload_strategy_context = NULL;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:188:5: error: expected declaration specifiers before ‘error’
         error = ext_log_upload_strategy_create(kaa_client_get_context(kaa_client),
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:191:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:196:5: error: expected declaration specifiers before ‘error’
         error = ext_log_upload_strategy_set_threshold_count(log_upload_strategy_context,
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:199:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:204:5: error: expected declaration specifiers before ‘error’
         error = kaa_logging_set_strategy(kaa_client_get_context(kaa_client)->log_collector,
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:207:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:215:5: error: expected declaration specifiers before ‘error’
         error = kaa_client_start(kaa_client, temperature_update,
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:218:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:226:5: error: expected declaration specifiers before ‘kaa_client_destroy’
         kaa_client_destroy(kaa_client);
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:228:5: error: expected declaration specifiers before ‘return’
         return EXIT_SUCCESS;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:229:1: error: expected declaration specifiers before ‘}’ token

预期声明是什么意思?我应该做某种形式的声明吗?原始演示代码运行良好。下面是 kaa_demo.c 的代码:

4

1 回答 1

1

kaa_demo.c你有:

int main(void)
//{
    //{
        //float batt; float cel; float wt;

        //for (batt = 4.99 && cel = 3.99 && wt = 2.99; batt > 0 && cel > 0 && wt > 0; batt-- && cel-- && wt--){
            //  printf("%d\n",batt,cel,wt);
        //}
        //return 0;
    //}
//}


    /**
     * Initialise a board.
     */
    int ret = target_initialize();
    if (ret < 0) {

由于没有左大括号,编译器认为您正在尝试使用K&R 样式的函数参数列表。只需添加一个大括号:

int main(void)
{ //<----Notice the new brace
//{
    //{
        //float batt; float cel; float wt;

        //for (batt = 4.99 && cel = 3.99 && wt = 2.99; batt > 0 && cel > 0 && wt > 0; batt-- && cel-- && wt--){
            //  printf("%d\n",batt,cel,wt);
        //}
        //return 0;
    //}
//}


    /**
     * Initialise a board.
     */
    int ret = target_initialize();
    if (ret < 0) {

要回答您从技术上提出的问题,

预期声明是什么意思?

编译器期望函数范围的开头,即开头{,或者函数参数列表。ret然后从它的角度来看已经声明了第二个引用,因此您不能再次声明它。它期待一个新的声明。

于 2017-01-16T05:28:15.937 回答