g ++内联未能调用always_inline“ int _rdrand16_step()”

时间:2018-09-07 14:17:08

标签: c++ g++

我使用Intel函数_rdrand16_step()编写了一个代码,在Windows(Visual Studio 2017)上工作正常,但在Linux(g ++)上我无法正常工作。 我在代码中两次调用了该函数:

#include <immintrin.h>
...
unsigned short val = 0;
if (_rdrand16_step(&val))
...
_rdrand16_step(&val);
...

和g ++输出:

/usr/lib/gcc/x86_64-linux-gnu/8/include/immintrin.h: In member function ‘int otp_s7c::crypt(std::__cxx11::string, std::__cxx11::string, long long unsigned int)’:
/usr/lib/gcc/x86_64-linux-gnu/8/include/immintrin.h:129:1: error: inlining failed in call to always_inline ‘int _rdrand16_step(short unsigned int*)’: target specific option mismatch
 _rdrand16_step (unsigned short *__P)
 ^~~~~~~~~~~~~~
otp_s7c.cpp:139:24: note: called from here
      if (_rdrand16_step(&val))
          ~~~~~~~~~~~~~~^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/8/include/immintrin.h:129:1: error: inlining failed in call to always_inline ‘int _rdrand16_step(short unsigned int*)’: target specific option mismatch
 _rdrand16_step (unsigned short *__P)
 ^~~~~~~~~~~~~~
otp_s7c.cpp:148:23: note: called from here
         _rdrand16_step(&val);
         ~~~~~~~~~~~~~~^~~~~~

2 个答案:

答案 0 :(得分:1)

这是一个令人误解的错误消息,其原因是您并未真正告诉编译器目标体系结构支持RDRAND指令(据我所知,这里的重要部分是“特定于目标的选项”不匹配”部分。

在编译器标志中添加-mrdrnd似乎可以解决此问题。


比较Compiler Explorer withwithout标志上的示例

答案 1 :(得分:0)

一周前,我在cmake遇到了同样的问题。但是,当添加以下命令时,此问题就消失了。

SET(CMAKE_C_FLAGS "-mrdrnd")