【问题标题】:Clang. How to overcome "unknown builtin" error message铛。如何克服“未知内置”错误消息
【发布时间】:2013-08-18 12:34:19
【问题描述】:

我有一个程序可以设置 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'

【问题讨论】:

    标签: c++ c gcc compiler-construction clang


    【解决方案1】:

    当您进行项目配置时,一定有什么有趣的地方。例如,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并添加包含路径时才会发生,它不起作用吗?我很确定我添加了所有包含路径,所以这不太可能是原因。
    • 内建可以由编译器直接定义,而无需符号实际存在于任何包含文件中。相反,编译器有一个内部“内置”列表,它会在编译时查找和处理。
    • @Brian,我有点明白内置的想法。但是在这种情况下,让我感到惊讶的是,当我直接调用 clang 时,我没有收到错误,但是当我通过设置 compilerInstance 通过我的程序调用时,我得到了错误。我需要在设置时添加任何路径吗?这是我的代码的链接...pastebin.com/cc0rMFr6
    猜你喜欢
    • 2014-08-21
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 2020-11-02
    • 2020-09-08
    • 1970-01-01
    相关资源
    最近更新 更多