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

用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的头文件路径放在最前面。

发布了85 篇原创文章 · 获赞 9 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/jimmyleeee/article/details/90202026