简体   繁体   English

Linux C++ 编译错误<emmintrin.h></emmintrin.h>

[英]Linux C++ compilation error <emmintrin.h>

I am trying to load images using stb_image.h but I am getting two compiler errors in the version of <emmintrin.h> provided by gcc. I figure that there is probably a compiler option that is needed but I haven't been able to find what it is.我正在尝试使用 stb_image.h 加载图像,但在 gcc 提供的 <emmintrin.h> 版本中出现两个编译器错误。我认为可能需要一个编译器选项,但我无法做到找到它是什么。

Error codes:错误代码:

/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/emmintrin.h:1230:10: error: the last argument must be an 8-bit immediate
 1230 |   return (__m128i)__builtin_ia32_pslldqi128 (__A, __N * 8);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/emmintrin.h:1224:10: error: the last argument must be an 8-bit immediate
 1224 |   return (__m128i)__builtin_ia32_psrldqi128 (__A, __N * 8);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Relevant code from <emmintrin.h>: <emmintrin.h> 中的相关代码:

extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_srli_si128 (__m128i __A, const int __N)
{
  return (__m128i)__builtin_ia32_psrldqi128 (__A, __N * 8);
}

extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_slli_si128 (__m128i __A, const int __N)
{
  return (__m128i)__builtin_ia32_pslldqi128 (__A, __N * 8);
}

Edit: It has something to do with spdlog.编辑:它与 spdlog 有关。 I removed all includes of spdlog and changed my logging macros to nothing and it compiled successfully我删除了所有包含的 spdlog 并将我的日志记录宏更改为空并且它编译成功

Minimum reproducible example:最小可重现示例:

main.cpp主.cpp

#include "pch.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

int main() {
    return 0;
}

pch.h: pch.h:

#include <spdlog/spdlog.h>

cmakelists.txt: cmakelists.txt:

cmake_minimum_required(VERSION 3.22)
project(untitled2)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_COMPILER /usr/bin/g++)

add_executable(untitled2 main.cpp stb_image.h pch.h)
target_precompile_headers(untitled2 PUBLIC pch.h)

add_subdirectory(spdlog)
target_link_libraries(untitled2 spdlog)

It happens when your program isn't compiling with optimizations but emmintrin.h is selecting the optimized versions of _mm_srli_si128 and _mm_slli_si128 because fmt (a dependency of spdlog) defines __OPTIMIZE__ here .当您的程序未使用优化进行编译但emmintrin.h正在选择_mm_srli_si128_mm_slli_si128的优化版本时,就会发生这种情况,因为 fmt(spdlog 的依赖项) 在此处定义了__OPTIMIZE__

For more information, take a look at https://github.com/nothings/stb/discussions/1432#discussioncomment-4595273 .有关详细信息,请查看https://github.com/nothings/stb/discussions/1432#discussioncomment-4595273

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM