This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

newlib vs SEGGER runtime Library cJSON library

Hi DevZone,

We are trying to move our existing application from SEGGER compilation to a GCC build for CI / CD purposes. However we are seeing a strange bug with uint64_t types and our cJSON library.

We can compile the following snippet in both applications, however, only the SEGGER build succesfully prints out the formatted cJSON string:

cJSON *json_object = cJSON_CreateObject();

/* Timestamp and ID are the same for all measurement types */
uint64_t integer_64 = (((uint64_t)1) << 63);
uint32_t integer_32 = 684956;
cJSON_AddNumberToObject(json_object, "integer64", integer_64);
cJSON_AddNumberToObject(json_object, "integer32", integer_32);

char* json_string = cJSON_PrintUnformatted(json_object);
if (!json_string) {
	NRF_LOG_ERROR("Could not create string");
}
NRF_LOG_INFO("%llu: %s", integer_64, json_string);

Which outputs:

GCC Output:
<info> main: 0: {"integer64":,"integer32":684956}

SEGGER Output:
<info> main: 0: {"integer64":9223372036854776000,"integer32":684956}

I tried printing out NRF_LOG_INFO("Newlib: %s", _NEWLIB_VERSION); and it seems that SEGGER is using a different libc implementation as __NEWLIB_VERSION is only defined in the GCC build, so this must be a clue in what's going wrong. I don't know why newlib wouldn't work with the above code. 

Any help in figuring out how to get this working under GCC? Thank you for the help.

Best regards,

Mattia

Parents
  • Hello,

    Nordic is not responsible for the libc implementation and what is supported. This is something you need to ask the developers of the toolchain about.

    What you can try is either disable the newlib nano flag in the makefile, to compile the full newlib instead of the nano version, or you can find a workaround where you for instance print the uint64 number as two 32 bit numbers instead.

Reply
  • Hello,

    Nordic is not responsible for the libc implementation and what is supported. This is something you need to ask the developers of the toolchain about.

    What you can try is either disable the newlib nano flag in the makefile, to compile the full newlib instead of the nano version, or you can find a workaround where you for instance print the uint64 number as two 32 bit numbers instead.

Children
No Data
Related