Build error: libubox/blobmsg_json.h:42: undefined reference to `blobmsg_format_json_with_cb'

OpenWrt 18.06.
I am developing a daemon that acts mostly as a ubus server, providing data to be read on LuCi. That part has gone well, and the libubus blobmsg functions are being used absolutely fine.

Now I would like to poll iwinfo info ubus command to collect some data for use in the C program. Using the ubus example/client.c I have managed to get a response from iwinfo
with the callback 'ret' value being 0. Now I would like to parse the json response to see the data that has been returned.
This article (invoke_client.c) provides an example using the ubus_invoke() method instead of ubus_invoke_async(). The callback from this provides the json response as struct blob_attr *msg. (So does the ubus_invoke_async() if I use the data_cb instead of complete_cb)

The point:
Only when I try to use the function blobmsg_format_json_with_cb, I get build error:

.../staging_dir/target-mipsel_24kc_musl/usr/include/libubox/blobmsg_json.h:42: undefined reference to `blobmsg_format_json_with_cb'

The function is obviously there in the blobmsg_json.h file at the location mentioned. What could be the problem here?

blobmsg_json.h ->

My Code:

static struct ubus_request req;
uint32_t id;
if (ubus_lookup_id(ctx, "network.wireless", &id)) {
    fprintf(stderr, "Failed to look up iwinfo object\n");
    add_error("Software", "Unable to detect connectivity, iwinfo unavailable");
	return -1;
blob_buf_init(&client, 0);
 //blobmsg_add_string(&client, "device", "wlan0");
 //ubus_invoke_async(ctx, id, "status", client.head, &req);
 //req.fd_cb = iwinfo_info_fd_cb;
 //req.complete_cb = iwinfo_info_complete_cb;
 //ubus_complete_request_async(ctx, &req);
int ret = ubus_invoke(ctx, id, "status", client.head, iwinfo_info_complete_cb, NULL, 2000);


static void iwinfo_info_complete_cb(struct ubus_request *req, int ret, struct blob_attr *msg){
	fprintf(stderr, "json: %s\n", blobmsg_format_json_indent(msg, true, 0));
    fprintf(stderr, "completed iwinfo request, ret: %d\n", ret);


Try to add the lblobmsg_json compilation flag to Makefile and +libblobmsg-json to OpenWRT package Makefile.
libblobmsg-json is a separated library in libubox package, because of that you need to add more dependencies to solve this issue.

From libubox/Makefile

define Package/libblobmsg-json
  TITLE:=blobmsg <-> json conversion library
  DEPENDS:=+libjson-c +libubox
1 Like

Thank you very much for a good suggestion @Keynib .

I already have +libblobmsg-json as a dependency in the Makefile, but I was missing -lblobmsg_json from the TARGET_LDFLAGS.

Adding this solved my issue.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.