0

What do these errors mean? I was following a guide after generating the Kaa SDK and running it but I have gotten these errors.

 /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

What does it mean by expected declaration ? Am I supposed to do some form of declaration? The original demo code ran perfectly. Below is the code for kaa_demo.c:

Ben Sin
  • 1
  • 1
  • 5
  • 1
    Could you post the code that causes this error? It sounds like there's a formatting issue prior to kaa_demo.c line 145 – Tim Sweet Jan 16 '17 at 05:14

1 Answers1

1

In kaa_demo.c you have:

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) {

Since there is no opening brace the compiler thinks you're trying to use the K&R-style function parameter list. Simply add a brace:

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) {

To answer the question you technically asked,

What does it mean by expected declaration ?

The compiler was expecting either the beginning of a function scope, i.e. the opening {, or a function parameter list. Then the second reference to ret which has already been declared from its point of view, thus you cannot declare it again. It was expecting a new declaration.

Community
  • 1
  • 1
Tim Sweet
  • 636
  • 5
  • 15
  • sorry.. i do not understand clearly. do u have an example for me or what should i do in my case for this ret? – Ben Sin Jan 16 '17 at 05:36
  • I've clarified my answer, look for the "//<----Notice the new brace" on the second line of the updated code. – Tim Sweet Jan 16 '17 at 05:40
  • Or, another way of looking at it, count the number of opening and closing braces between `int main(void)` and the end of the file. You'll find there is one more closing brace `}` than opening brace `{`. My updated code fixes this. – Tim Sweet Jan 16 '17 at 05:42
  • Its correct. i doublechecked with the original demo code that works – Ben Sin Jan 16 '17 at 05:47
  • i have one more error.. it seems major. im very sorry about it , im very keen on C but i have been stucked for days .. i have gotten segmentation error.. – Ben Sin Jan 16 '17 at 05:57
  • my other files seems to have errors. But those are generated from Kaa IOT platform – Ben Sin Jan 16 '17 at 05:57
  • @BenSin: segmentation fault is a new question. Please study how to create an MCVE ([MCVE]). – Jonathan Leffler Jan 16 '17 at 05:58