jow- / ucode

JavaScript-like language with optional templating
ISC License
87 stars 24 forks source link

error: static declaration of ‘json_tokener_get_parse_end’ follows non-static declaration #186

Closed matrixpool closed 2 months ago

matrixpool commented 5 months ago

hi, compild libucode and output: In file included from /opt/ucode/lib.c:45: /opt/ucode/json-c-compat.h:28:22: error: static declaration of ‘json_tokener_get_parse_end’ follows non-static declaration 28 | static inline size_t json_tokener_get_parse_end(struct json_tokener tok) { | ^~~~~~ In file included from /usr/include/json-c/json.h:30, from /opt/ucode/json-c-compat.h:22, from /opt/ucode/lib.c:45: /usr/include/json-c/json_tokener.h:136:20: note: previous declaration of ‘json_tokener_get_parse_end’ with type ‘size_t(struct json_tokener )’ {aka ‘long unsigned int(struct json_tokener )’} 136 | JSON_EXPORT size_t json_tokener_get_parse_end(struct json_tokener tok); | ^~~~~~ In file included from /opt/ucode/lib.c:45: /opt/ucode/json-c-compat.h:34:35: error: static declaration of ‘json_object_new_array_ext’ follows non-static declaration 34 | static inline struct json_object json_object_new_array_ext(int size) { | ^~~~~~~~~ In file included from /usr/include/json-c/json.h:27, from /opt/ucode/json-c-compat.h:22, from /opt/ucode/lib.c:45: /usr/include/json-c/json_object.h:536:33: note: previous declaration of ‘json_object_new_array_ext’ with type ‘struct json_object (int)’ 536 | JSON_EXPORT struct json_object json_object_new_array_ext(int initial_size); | ^~~~~~~~~ In file included from /opt/ucode/lib.c:45: /opt/ucode/json-c-compat.h:41:35: error: static declaration of ‘json_object_new_uint64’ follows non-static declaration 41 | static inline struct json_object json_object_new_uint64(uint64_t i) { | ^~~~~~ In file included from /usr/include/json-c/json.h:27, from /opt/ucode/json-c-compat.h:22, from /opt/ucode/lib.c:45: /usr/include/json-c/json_object.h:699:33: note: previous declaration of ‘json_object_new_uint64’ with type ‘struct json_object (uint64_t)’ {aka ‘struct json_object (long unsigned int)’} 699 | JSON_EXPORT struct json_object json_object_new_uint64(uint64_t i); | ^~~~~~ In file included from /opt/ucode/lib.c:45: /opt/ucode/json-c-compat.h:45:24: error: static declaration of ‘json_object_get_uint64’ follows non-static declaration 45 | static inline uint64_t json_object_get_uint64(const struct json_object obj) { | ^~~~~~ In file included from /usr/include/json-c/json.h:27, from /opt/ucode/json-c-compat.h:22, from /opt/ucode/lib.c:45: /usr/include/json-c/json_object.h:773:22: note: previous declaration of ‘json_object_get_uint64’ with type ‘uint64_t(const struct json_object )’ {aka ‘long unsigned int(const struct json_object )’} 773 | JSON_EXPORT uint64_t json_object_get_uint64(const struct json_object *obj); | ^~~~~~ make[2]: [CMakeFiles/libucode.dir/build.make:90: CMakeFiles/libucode.dir/lib.c.o] Error 1 make[1]: [CMakeFiles/Makefile2:128: CMakeFiles/libucode.dir/all] Error 2 make: *** [Makefile:136: all] Error 2

how to resolve?

jow- commented 4 months ago

Try cleaning your build tree (git clean -f -d -x), then run cmake . again to re-detect libjson-c features, then try to build again. If it still fails, you need to provide more details about your environment such as Operating System, used toolchain etc.

thamesview commented 3 months ago

I had the same problem with static inline vs non-static declaration errors.

I've resolved the issue by adding:

#define JSON_EXPORT static inline

before #include <json-c/json.h> in json-c-compat.h

I was following steps for building ucode for 'Other Linux systems' using:

ucode git hash 55ee75b6e0 - latest ucode commit dated 13 March 23 json-c git hash 0bc2dd5e60 - commit dated 2 March 23

git clone https://github.com/jow-/ucode.git
cd ucode/
cmake -DUBUS_SUPPORT=OFF -DUCI_SUPPORT=OFF -DULOOP_SUPPORT=OFF .
make
sudo make install

By default JSON_EXPORT is defined as extern so this generates non-static declarations for the same set of compat functions - which are in conflict with each other.

The root cause of the errors might be that:

check_symbol_exists(json_tokener_get_parse_end "json-c/json.h" HAVE_PARSE_END) check_symbol_exists(json_object_new_array_ext "json-c/json.h" HAVE_ARRAY_EXT) check_symbol_exists(json_object_new_uint64 "json-c/json.h" HAVE_JSON_UINT64)

are not correctly detecting presence of these functions - but I didn't have time to investigate this in more detail - just included a quick hack to define JSON_EXPORT in json-c-compat.h file : )