gpt4 book ai didi

c++ - 在 Visual Studio 中编译 gcc 代码导致错误 C3646 : '__attribute__' : unknown override specifier

转载 作者:搜寻专家 更新时间:2023-10-31 02:20:16 27 4
gpt4 key购买 nike

我收到以下错误:

error C3646: '__attribute__': unknown override specifier

代码:

LEMUR_PREALIGN char _stack[ sizeof(_Type) * _Count ] LEMUR_POSTALIGN;

完整的错误:

1>c:\program files\indri\indri 5.9\include\indri\greedy_vector(52): error C3646: '__attribute__': unknown override specifier

附加信息:我正在尝试在 Visual Studio 项目中使用 indri.lib。

最佳答案

__attribute__ 命令是 gcc 的编译器特定命令。它用在 this file 的第 52 行与 ((align)) command ,其中:

Specifies a minimum alignment (in bytes) for variables of the specified type

Visual studio 实际上有类似的对齐命令:align .但是有两个问题:

  1. __declspec(align(#)) 不支持默认的:__attribute__ ((aligned)) 行为将:

Align a type to the maximum useful alignment for the target machine you are compiling for

  1. __declspec(align(#)) 是一个前缀。 __attribute__((aligned(#))) 是一个后缀。这意味着您的实际代码需要在位置上有所不同:

struct S { short f[3]; } __attribute__ ((对齐));//gcc 对齐定义
__declspec(align(16)) strict S { short f[3]; };//MSVC 对齐方式

这里的要点是,编译器使用 #ifdef 编译任何使用 __attribute__ ((aligned)) 的行并编写您自己的 可能会更好__declspec(对齐(#))

有关详细信息,请参阅:GCC vs MSVC class packing and alignment


在对 lemur_platform.h 进行更多研究后,看起来代码已经为您完成了上述所有工作!您会注意到 #define LEMUR_POSTALIGN __attribute__ ((aligned)) 包含在 #ifndef WIN32 中。所以您需要做的是在您的 Visual Studio 项目中定义 WIN32!

关于c++ - 在 Visual Studio 中编译 gcc 代码导致错误 C3646 : '__attribute__' : unknown override specifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32923135/

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