代码之家  ›  专栏  ›  技术社区  ›  Samega 7Cattac

g++内联调用always\u inline“int\u rdrand16\u step()”失败

  •  2
  • Samega 7Cattac  · 技术社区  · 6 年前

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

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

    /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);
             ~~~~~~~~~~~~~~^~~~~~
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   hlt    6 年前

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

    添加 -mrdrnd


    比较编译器资源管理器上的一个示例 with without 旗帜

        2
  •  0
  •   Land    5 年前

    我也有同样的问题 cmake 一周前。但是当添加以下命令时,这个问题就消失了。

    SET(CMAKE_C_FLAGS "-mrdrnd")
    
    推荐文章