用Clang编译出现错误的解决方法

36 篇文章 0 订阅
32 篇文章 0 订阅

用Clang编译器编译opencv,遇到如下错误:

In file included from /tool/app/gnu/gcc-8.2.0/lib/gcc/x86_64-redhat-linux/8.2.0/include/emmintrin.h:31:
/tool/app/gnu/gcc-8.2.0/lib/gcc/x86_64-redhat-linux/8.2.0/include/xmmintrin.h:130:19: error: use of undeclared identifier '__builtin_ia32_addss'
  return (__m128) __builtin_ia32_addss ((__v4sf)__A, (__v4sf)__B);
                  ^
/tool/app/gnu/gcc-8.2.0/lib/gcc/x86_64-redhat-linux/8.2.0/include/xmmintrin.h:136:19: error: use of undeclared identifier '__builtin_ia32_subss'
  return (__m128) __builtin_ia32_subss ((__v4sf)__A, (__v4sf)__B);
                  ^
/tool/app/gnu/gcc-8.2.0/lib/gcc/x86_64-redhat-linux/8.2.0/include/xmmintrin.h:142:19: error: use of undeclared identifier '__builtin_ia32_mulss'
  return (__m128) __builtin_ia32_mulss ((__v4sf)__A, (__v4sf)__B);
                  ^
/tool/app/gnu/gcc-8.2.0/lib/gcc/x86_64-redhat-linux/8.2.0/include/xmmintrin.h:148:19: error: use of undeclared identifier '__builtin_ia32_divss';
      did you mean '__builtin_ia32_minss'?
  return (__m128) __builtin_ia32_divss ((__v4sf)__A, (__v4sf)__B);
 

解决方法:参考:http://clang.llvm.org/compatibility.html#vector_builtins

"missing" vector __builtin functions

The Intel and AMD manuals document a number "<*mmintrin.h>" header files, which define a standardized API for accessing vector operations on X86 CPUs. These functions have names like _mm_xor_ps and _mm256_addsub_pd. Compilers have leeway to implement these functions however they want. Since Clang supports an excellent set of native vector operations, the Clang headers implement these interfaces in terms of the native vector operations.

In contrast, GCC implements these functions mostly as a 1-to-1 mapping to builtin function calls, like __builtin_ia32_paddw128. These builtin functions are an internal implementation detail of GCC, and are not portable to the Intel compiler, the Microsoft compiler, or Clang. If you get build errors mentioning these, the fix is simple: switch to the *mmintrin.h functions.

The same issue occurs for NEON and Altivec for the ARM and PowerPC architectures respectively. For these, make sure to use the <arm_neon.h> and <altivec.h> headers.

For x86 architectures this script should help with the manual migration process. It will rewrite your source files in place to use the APIs instead of builtin function calls. Just call it like this:

  builtins.py *.c *.h

and it will rewrite all of the .c and .h files in the current directory to use the API calls instead of calls like __builtin_ia32_paddw128.

解决方案就是: 将Clang的头文件路径设置在gcc的头文件路径之前查找即可。例如,可以定义C_INCLUDE_PATH和CPLUS_INCLUDE_PATH,把clang的头文件路径放在最前面。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用Clang编译代码时,如果出现"segmentation fault"的提示,这通常意味着程序在运行时访问了无效的内存地址,导致了崩溃。 "Segmentation fault"是一种常见的运行时错误,它通常是由以下几种情况引起的: 1. 空指针引用:当你尝试访问一个空指针时,会导致"segmentation fault"错误。这通常是因为你没有正确初始化指针或者指针指向的对象已经被释放。 2. 数组越界:当你尝试访问数组中超出有效索引范围的元素时,会导致"segmentation fault"错误。这通常是因为你没有正确计算数组的大小或者使用了无效的索引。 3. 栈溢出:当你在递归函数中使用了过多的栈空间,或者在局部变量中分配了过多的内存,会导致栈溢出,进而引发"segmentation fault"错误。 4. 野指针:当你使用了一个未初始化的指针或者已经被释放的指针时,会导致"segmentation fault"错误解决"segmentation fault"错误方法包括: 1. 检查空指针:确保你在使用指针之前对其进行了正确的初始化,并且在使用完毕后将其置为NULL。 2. 检查数组越界:确保你在访问数组元素时使用了有效的索引,并且数组的大小足够容纳你的访问。 3. 检查递归和局部变量:确保你在递归函数中使用了合理的终止条件,并且在使用局部变量时不会超出栈的容量。 4. 避免野指针:确保你在使用指针之前对其进行了正确的初始化,并且在释放指针后不再使用它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值