3 Replies Latest reply on Jan 22, 2015 2:45 AM by mhahn

    Error in creating json object in c programm in galileo

    chandu_india

      i am using own builded image with include dev tools like gcc and others, when i am try to compile my jsonexam1.c(code pasted below) i got some errors,need some help to solve those

       

      code:

       

       

      #include <json-c/json.h>

      #include <stdio.h>

       

       

      int main() {

        /*Creating a json object*/

        json_object * jobj = json_object_new_object();

       

       

        /*Creating a json array*/

        json_object *jarray = json_object_new_array();

       

       

        /*Creating json strings*/

        json_object *jstring[3];

        jstring[0] = json_object_new_string("c");

        jstring[1] = json_object_new_string("c++");

        jstring[2] = json_object_new_string("php");

       

       

        /*Adding the above created json strings to the array*/

        int i;

        for (i=0;i<3; i++) {

          json_object_array_put_idx(jarray,i+2, jstring[i]);

        }

       

       

        /*Form the json object*/

        json_object_object_add(jobj,"Categories", jarray);

       

       

        /*Now printing the json object*/

        printf ("The json object created: %sn",json_object_to_json_string(jobj));

       

       

      }

       

       

      Error:

       

       

      gcc  jsonexam1.c -o json

      /tmp/cc7RaTzP.o: In function `main':

      jsonexam1.c:(.text+0xa): undefined reference to `json_object_new_object'

      jsonexam1.c:(.text+0x13): undefined reference to `json_object_new_array'

      jsonexam1.c:(.text+0x23): undefined reference to `json_object_new_string'

      jsonexam1.c:(.text+0x33): undefined reference to `json_object_new_string'

      jsonexam1.c:(.text+0x43): undefined reference to `json_object_new_string'

      jsonexam1.c:(.text+0x74): undefined reference to `json_object_array_put_idx'

      jsonexam1.c:(.text+0x9b): undefined reference to `json_object_object_add'

      jsonexam1.c:(.text+0xa7): undefined reference to `json_object_to_json_string'

      collect2: error: ld returned 1 exit status