c - gcc不包含c头文件json-c

标签 c json gcc header-files json-c

在 Macbook 上,我正在使用 json-c( https://github.com/json-c/json-c ) 制作一些东西

gcc a.c
a.c:1:10: fatal error: 'json.h' file not found
#include "json.h"
          ^
1 error generated.`>

当我尝试编译它时,

它打印出错误,但包含文件中有 json.h 文件。

> cd /usr/local/include/json-c/
> ls
arraylist.h            json_config.h          json_tokener.h
bits.h                 json_inttypes.h        json_util.h
debug.h                json_object.h          linkhash.h
json.h                 json_object_iterator.h printbuf.h
json_c_version.h       json_object_private.h  random_seed.h

/usr/include/json-c/json.h 肯定存在

最佳答案

编译器的包含路径中可能没有 json-c 子目录。

如果幸运的话,您可以将其添加到您的包含内容中:

#include "json-c/json.h"

这仅在该 header 是独立的情况下才有效,即它不引用 json-c/ 中的任何其他 header 。

如果失败,您必须在调用它时告诉编译器:

$ gcc -I/usr/local/include/json-c/ a.c

关于c - gcc不包含c头文件json-c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37654661/

相关文章:

c - 链表,删除尾函数

c - 错误 : Conflicting types for 'remove'

json - 动态返回不同类型的 JSON 结构?

c# - 使用不同类型序列化/反序列化 System.Object

objective-c - 使用 Apple 核心库(例如 Foundation.h)在 OSX 上使用 gcc-4.7 编译 Objective C 文件

c - strcat 返回错误的字符

Javascript,没有时区的 Date.parse

macos - 如何在 macOS 10.13 上安装 gcc@7?

c - __attribute__ 优化,指定多个标志,以及不同 -O 级别的失败代码

c - 如何使用C代码更改CPU频率?