clang -cc1找不到头文件

$./clang -cc1 -emit-pth test/test.h -o test/test.h.pth
test/test.h:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.

查找发现,clang -cc1选项默认在自己的目录搜索:

Builtin includes
Clang tools need their builtin headers and search for them the same way Clang does. Thus, the default location to look for builtin headers is in a path $(dirname /path/to/tool)/../lib/clang/3.3/include relative to the tool binary. This works out-of-the-box for tools running from llvm’s toplevel binary directory after building clang-headers, or if the tool is running from the binary directory of a clang install next to the clang binary.

Tips: if your tool fails to find stddef.h or similar headers, call the tool with -v and look at the search paths it looks through.

所以,我们要手动加上头文件的路径了,

 ./clang -cc1 -I/usr/include/ -I/usr/lib/gcc/x86_64-linux-gnu/4.8/include  -emit-pth test/test.h -o test/test.h.pth

其中 -I/usr/include 是找 stdio.h,而 I/usr/lib/gcc/x86_64-linux-gnu/4.8/include 是找 stddef.h.不过每次这样加路径似乎很麻烦,所以,也可以写进/etc/bash.bashrc:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值