using jansson with stm32 in eclipse kepler on mac os x

543 views
Skip to first unread message

Ilya Mordasov

unread,
Nov 17, 2015, 6:42:58 AM11/17/15
to Jansson users
Hi there!

I'm trying to include jansson library into my test project for stm32f4discovery using eclipse kepler on mac os x el capitan.

So, I downloaded jansson-2.7.tar.bz2, run the terminal and execute the next commands:

brew install jansson

after that i found files:
jansson.h
jansson_config
.h
libjansson
.a

in the /usr/local/Cellar/jansson directory

The next step is launching my IDE

I have a directory for jansson, which has 2 subdirectories inc and lib

I put jansson.h and jansson_config.h into inc subdir and libjansson.a in lib subdir

So, now I have this structure
jansson
   
|
   inc
     
|
     jansson
.h
     jansson_config
.h
   lib
     
|
     libjansson
.a

In the project properties I went to C/C++ General > Path and Symbols > Includes, pressed "add" and entered jansson/inc
Also I went to C/C++ Build > Settings > Tool Settings > Cross ARM C++ Linker > Miscellaneous and press "add", choice File system and pointed to my libjansson.a file

I pressed Apply and Ok

After compiling the project I got the next issues:
Description Resource Path Location Type
undefined reference to `json_delete' jansson.h /jansson_test/json/inc line 112 C/C++ Problem
undefined reference to `json_object_iter' main.c /jansson_test/src line 80 C/C++ Problem
undefined reference to `json_object_size' main.c /jansson_test/src line 77 C/C++ Problem
undefined reference to `json_real_value' main.c /jansson_test/src line 111 C/C++ Problem
undefined reference to `json_integer_value' main.c /jansson_test/src line 106 C/C++ Problem
undefined reference to `json_string_value' main.c /jansson_test/src line 101 C/C++ Problem
make: *** [jansson_test.elf] Error 1 jansson_test C/C++ Problem
undefined reference to `json_loads' main.c /jansson_test/src line 140 C/C++ Problem
undefined reference to `json_array_get' main.c /jansson_test/src line 95 C/C++ Problem
undefined reference to `json_array_size' main.c /jansson_test/src line 90 C/C++ Problem
undefined reference to `json_object_iter_value' main.c /jansson_test/src line 80 C/C++ Problem
undefined reference to `json_object_iter_next' main.c /jansson_test/src line 80 C/C++ Problem
undefined reference to `json_object_key_to_iter' main.c /jansson_test/src line 80 C/C++ Problem
undefined reference to `json_object_iter_key' main.c /jansson_test/src line 80 C/C++ Problem


I'm using simple_son example to parse son

#include <stdio.h>

#include <stdlib.h>

#include "jansson.h"

#include "diag/Trace.h"


#define MAX_CHARS 4096


#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wunused-parameter"

#pragma GCC diagnostic ignored "-Wmissing-declarations"

#pragma GCC diagnostic ignored "-Wreturn-type"


/* forward refs */

void print_json(json_t *root);

void print_json_aux(json_t *element, int indent);

void print_json_indent(int indent);

const char *json_plural(int count);

void print_json_object(json_t *element, int indent);

void print_json_array(json_t *element, int indent);

void print_json_string(json_t *element, int indent);

void print_json_integer(json_t *element, int indent);

void print_json_real(json_t *element, int indent);

void print_json_true(json_t *element, int indent);

void print_json_false(json_t *element, int indent);

void print_json_null(json_t *element, int indent);


void print_json(json_t *root) {

    print_json_aux(root, 0);

}


void print_json_aux(json_t *element, int indent) {

    switch (json_typeof(element)) {

    case JSON_OBJECT:

        print_json_object(element, indent);

        break;

    case JSON_ARRAY:

        print_json_array(element, indent);

        break;

    case JSON_STRING:

        print_json_string(element, indent);

        break;

    case JSON_INTEGER:

        print_json_integer(element, indent);

        break;

    case JSON_REAL:

        print_json_real(element, indent);

        break;

    case JSON_TRUE:

        print_json_true(element, indent);

        break;

    case JSON_FALSE:

        print_json_false(element, indent);

        break;

    case JSON_NULL:

        print_json_null(element, indent);

        break;

    default:

        fprintf(stderr, "unrecognized JSON type %d\n", json_typeof(element));

    }

}


void print_json_indent(int indent) {

    int i;

    for (i = 0; i < indent; i++) { putchar(' '); }

}


const char *json_plural(int count) {

    return count == 1 ? "" : "s";

}


void print_json_object(json_t *element, int indent) {

    size_t size;

    const char *key;

    json_t *value;


    print_json_indent(indent);

    size = json_object_size(element);


    printf("JSON Object of %ld pair%s:\n", size, json_plural(size));

    json_object_foreach(element, key, value) {

        print_json_indent(indent + 2);

        printf("JSON Key: \"%s\"\n", key);

        print_json_aux(value, indent + 2);

    }


}


void print_json_array(json_t *element, int indent) {

    size_t i;

    size_t size = json_array_size(element);

    print_json_indent(indent);


    printf("JSON Array of %ld element%s:\n", size, json_plural(size));

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

        print_json_aux(json_array_get(element, i), indent + 2);

    }

}


void print_json_string(json_t *element, int indent) {

    print_json_indent(indent);

    printf("JSON String: \"%s\"\n", json_string_value(element));

}


void print_json_integer(json_t *element, int indent) {

    print_json_indent(indent);

    printf("JSON Integer: \"%" JSON_INTEGER_FORMAT "\"\n", json_integer_value(element));

}


void print_json_real(json_t *element, int indent) {

    print_json_indent(indent);

    printf("JSON Real: %f\n", json_real_value(element));

}


void print_json_true(json_t *element, int indent) {

    (void)element;

    print_json_indent(indent);

    printf("JSON True\n");

}


void print_json_false(json_t *element, int indent) {

    (void)element;

    print_json_indent(indent);

    printf("JSON False\n");

}


void print_json_null(json_t *element, int indent) {

    (void)element;

    print_json_indent(indent);

    printf("JSON Null\n");

}


/*

 * Parse text into a JSON object. If text is valid JSON, returns a

 * json_t structure, otherwise prints and error and returns null.

 */

json_t *load_json(const char *text) {

    json_t *root;

    json_error_t error;


    root = json_loads(text, 0, &error);


    if (root) {

        return root;

    } else {

        fprintf(stderr, "json error on line %d: %s\n", error.line, error.text);

        return (json_t *)0;

    }

}


char *read_line(char *line, int max_chars) {

    printf("Type some JSON > ");

    fflush(stdout);

    return fgets(line, max_chars, stdin);

}



int main(int argc, char *argv[]) {

    char line[MAX_CHARS] = "{\"code\": 200, \"message\": \"hello jansson!\", \"system\":{\"os\": \"Mac OS X\", \"version\":\"10.11.1\"}}";



        /* parse text into JSON structure */

        json_t *root = load_json(line);


        if (root) {

            /* print and release the JSON structure */

            print_json(root);

            json_decref(root);

        }


    return 0;

}


#pragma GCC diagnostic pop



I use arm-none-eabi compiler
Reply all
Reply to author
Forward
0 new messages