2

我正在测试用于解析和生成 CBOR 的库 libcbor-0.5.0,https: //libcbor.readthedocs.io/en/v0.5.0/index.html 。除 cjson2cbor.c 外,所有示例都正常运行。它需要 cJSON.h,所以我将https://github.com/DaveGamble/cJSON添加到我的项目中。

源代码:

void cjson_cbor_stream_decode(cJSON * source,
                              const struct cbor_callbacks *callbacks,
                              void * context)
{
    switch (source->type) {

[...]

case cJSON_Array:
        {
            callbacks->array_start(context, cJSON_GetArraySize(source));
            cJSON *item = source->child;
            while (item != NULL) {
                cjson_cbor_stream_decode(item, callbacks, context);
                item = item->next;
            }
            return;
        }
        case cJSON_Object:
        {
            callbacks->map_start(context, cJSON_GetArraySize(source));
            cJSON *item = source->child;
            while (item != NULL) {
                callbacks->string(context, (unsigned char *) item->string, strlen(item->string));
                cjson_cbor_stream_decode(item, callbacks, context);
                item = item->next;
            }
            return;
        }
[...]

}

...

JSON * json = cJSON_Parse(json_buffer);
cJSON_Delete(json);

如果我编译 cc cjson2cbor.c -lcbor -o cjson2cbor

它返回此错误:

Undefined symbols for architecture x86_64:
  "_cJSON_Delete", referenced from:
      _main in cjson2cbor-d7a32c.o
  "_cJSON_GetArraySize", referenced from:
      _cjson_cbor_stream_decode in cjson2cbor-d7a32c.o
  "_cJSON_Parse", referenced from:
      _main in cjson2cbor-d7a32c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
4

1 回答 1

0

添加作为社区 wiki 提供的答案@John-Bollinger,因此不会出现未回答的情况。

传入-lcjson链接命令。

于 2020-10-01T13:54:11.203 回答