在Visual Studio中编译gcc代码会导致错误C3646:'__attribute__':未知重写说明符 [英] Compiling gcc code in Visual Studio causes error C3646: '__attribute__': unknown override specifier
问题描述
错误C3646:'__attribute__':未知的重写说明符
代码:
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__':未知覆盖说明符
其他信息:我正在尝试在Visual Studio项目中使用indri.lib。
__属性__
命令是gcc的编译器特定命令。它用于此文件的第52行与 ((align))
命令,其中:
指定指定类型变量的最小对齐(以字节为单位)
Visual studio实际上有一个类似的对齐命令: align
。但有两个问题:
$ b
-
__ declspec(align(#))
不会支持默认行为:__ attribute__((aligned))
将一个类型与您正在编译的目标机器的最大有用对齐关联
-
__ declspec(align(#))
是一个前缀。__属性__((aligned(#)))
是后缀。这意味着您的实际代码需要在展示位置上有所不同:
struct S {short f [3 ]。 } __attribute__((aligned)); // gcc对齐定义
__declspec(align(16))strict S {short f [3]; }; // MSVC alignment
这里的要点是你可能会更好
#ifdef $ c $编译器使用
__ attribute__((aligned))
并烹饪您自己的__ declspec(align(#))
。
更多信息请参阅: GCC vs MSVC class packing and alignment
经过对lemur_platform的更多研究。看起来代码已经完成了所有上述工作!您会注意到
#define LEMUR_POSTALIGN __attribute__((aligned))
被封装在#ifndef WIN32
中。所以你需要做的是在你的Visual Studio项目中定义WIN32
!I am getting the following error:
error C3646: '__attribute__': unknown override specifier
Code:
LEMUR_PREALIGN char _stack[ sizeof(_Type) * _Count ] LEMUR_POSTALIGN;
Complete error:
1>c:\program files\indri\indri 5.9\include\indri\greedy_vector(52): error C3646: '__attribute__': unknown override specifier
Additional info: I am trying to use indri.lib in Visual Studio project.
解决方案The
__attribute__
command is a compiler specific command to gcc. And it is used on line 52 of this file with the((align))
command, which:Specifies a minimum alignment (in bytes) for variables of the specified type
Visual studio does in fact have a similar alignment command:
align
. But there are two problems:__declspec(align(#))
does not support the defaulted:__attribute__ ((aligned))
behavior which will:
Align a type to the maximum useful alignment for the target machine you are compiling for
__declspec(align(#))
is a prefix.__attribute__((aligned(#)))
is a suffix. This means that your actual code would need to differ on the placement:
struct S { short f[3]; } __attribute__ ((aligned)); // gcc alignment definition __declspec(align(16)) strict S { short f[3]; }; // MSVC alignment
The point here is you'd probably be better off
#ifdef
ing by compiler any line that uses__attribute__ ((aligned))
and cooking your own__declspec(align(#))
.For more info see: GCC vs MSVC class packing and alignment
After a bit more study into lemur_platform.h it looks like the code has already done all the above work for you! You'll notice that
#define LEMUR_POSTALIGN __attribute__ ((aligned))
is wrapped in an#ifndef WIN32
. So what you need to do is defineWIN32
in your Visual Studio project!这篇关于在Visual Studio中编译gcc代码会导致错误C3646:'__attribute__':未知重写说明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-