gpt4 book ai didi

c++ - g++ 内联调用 always_inline "int _rdrand16_step()"失败

转载 作者:太空狗 更新时间:2023-10-29 21:33:12 30 4
gpt4 key购买 nike

我使用英特尔函数 _rdrand16_step() 编写了一段代码,在 Windows(Visual Studio 2017)上运行良好,但在 Linux(g++)上我无法使其运行。我在我的代码中调用了该函数 2 次:

#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);
~~~~~~~~~~~~~~^~~~~~

最佳答案

这是一个有点误导性的错误消息,因为您实际上并没有告诉编译器您的目标体系结构支持 RDRAND 指令(据我所知,这里的重要部分是“目标特定选项”不匹配”部分在最后)。

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


比较 Compiler Explorer 上的示例 withwithout旗帜

关于c++ - g++ 内联调用 always_inline "int _rdrand16_step()"失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52224421/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com