簡體   English   中英

g++ 內聯調用 always_inline "int _rdrand16_step()" 失敗

[英]g++ inlining failed in call to always_inline "int _rdrand16_step()"

我使用英特爾函數_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 上帶有帶有標志的示例

一周前我在cmake遇到了同樣的問題。 但是當添加以下命令時,這個問題就消失了。

SET(CMAKE_C_FLAGS "-mrdrnd")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM