Compiling gcc code in Visual Studio causes error C3646: '__attribute__': unknown override specifier

回眸只為那壹抹淺笑 提交于 2019-12-04 04:57:18

问题


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.


回答1:


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:

  1. __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

  1. __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 #ifdefing 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 define WIN32 in your Visual Studio project!



来源:https://stackoverflow.com/questions/32923135/compiling-gcc-code-in-visual-studio-causes-error-c3646-attribute-unknown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!