Clang。如何解决“unknown builtin”错误消息

3
我有一个程序,它设置了clang编译器实例并使用HeaderSearchOptions类添加包含路径。当我在输入文件libavutil/samplefmt.c(来自ffmpeg软件包)上运行ParseAst时,在屏幕上会出现以下消息。基本上,它无法解析一些(gcc?)内置函数。如何摆脱这个错误?通常情况下,如果通过HeaderSearchOptions设置包含路径,我该如何确保不会错过来自我的gcc安装的所有包含路径?
谢谢!
#include "..." search starts here:
#include <...> search starts here:
 .
 /usr/include/freetype2
 /usr/include/fribidi
 /usr/local/include
 /usr/include/clang/Basic
 /opt/llvmrelease/bin/../lib/clang/3.4/include
 /usr/include/i386-linux-gnu
 /include
 /usr/include
End of search list.
In file included from libavutil/samplefmt.c:19:
libavutil/common.h:258:12: error: use of unknown builtin '__builtin_clz'
    return av_log2((x - 1) << 1); 
           ^
libavutil/intmath.h:89:23: note: expanded from macro 'av_log2'
#define av_log2       ff_log2
                      ^
libavutil/intmath.h:45:29: note: expanded from macro 'ff_log2'
#   define ff_log2(x) (31 - __builtin_clz((x)|1))
                            ^
libavutil/samplefmt.c:59:14: error: use of unknown builtin '__builtin_strlen'
        if (!strcmp(sample_fmt_info[i].name, name))
             ^
/usr/include/i386-linux-gnu/bits/string2.h:804:22: note: expanded from macro 'strcmp'
      && (__s1_len = __builtin_strlen (s1), __s2_len = __builtin_strlen (s2), \
                     ^
libavutil/samplefmt.c:59:14: note: did you mean '__builtin_strchr'?
/usr/include/i386-linux-gnu/bits/string2.h:804:22: note: expanded from macro 'strcmp'
      && (__s1_len = __builtin_strlen (s1), __s2_len = __builtin_strlen (s2), \
                     ^
libavutil/samplefmt.c:59:14: error: use of unknown builtin '__builtin_strcmp'
        if (!strcmp(sample_fmt_info[i].name, name))
             ^
/usr/include/i386-linux-gnu/bits/string2.h:807:9: note: expanded from macro 'strcmp'
1个回答

4

当您进行项目配置时,可能出现了一些问题。例如,ff_log2代码位于:

#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)

因此,您需要确保未定义HAVE_FAST_CLZ,这样就可以解决这个问题了。您可以采取类似的方法来修复strcmp


谢谢。我在config.*文件中有以下行:#define HAVE_FAST_CLZ 1。当我删除它时,编译就可以了。但令我惊讶的是,当我直接通过gcc编译项目时,没有内置错误(将HAVE_FAST_CLZ设置为1)。你能告诉我为什么只有当我设置clang并添加包含路径时,它才不起作用吗?我很确定我正在添加所有包含路径,所以这不太可能是原因。 - user763410
内置函数可以直接由编译器定义,而无需在任何包含文件中实际存在这些符号。相反,编译器拥有一个内部列表,它将在编译时查找和处理“内置函数”。 - Brian
@Brian,我有点理解内置函数的概念。但是在这种情况下,让我惊讶的是,当我直接调用clang时,我没有收到错误信息,但是当我通过设置compilerInstance来调用我的程序时,我却收到了错误信息。我需要在设置时添加任何路径吗?这是我的代码链接... http://pastebin.com/cc0rMFr6 - user763410

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接