2015-10-03 104 views
1

我收到以下錯誤:編譯在Visual Studio GCC代碼導致錯誤C3646: '__attribute__':未知重寫說明符

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。

+3

你介意提供你的代碼嗎?它應該是[MCVE](http://stackoverflow.com/help/mcve)。 – MikeCAT

+0

而你的標題和問題有不同的錯誤信息。 –

+0

'LEMUR_POSTALIGN'是什麼意思? http://www.lemurproject.org/doxygen/lemur/html/lemur-platform_8h.html – MikeCAT

回答

1

__attribute__命令是gcc的編譯器特定命令。

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

的Visual Studio事實上確實有類似的對齊命令:align它與((align)) command,它使用的線this file 52。但有兩個問題:

  1. __declspec(align(#))不支持拖欠:__attribute__ ((aligned))行爲,這將:

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

  • __declspec(align(#))是一個前綴。 __attribute__((aligned(#)))是後綴。這意味着你的實際代碼需要在放置不同:
  • struct S { short f[3]; } __attribute__ ((aligned)); // gcc alignment definition __declspec(align(16)) strict S { short f[3]; }; // MSVC alignment

    這裏的關鍵是,你可能會更好#ifdef ING由編譯器使用__attribute__ ((aligned))任何線和烹飪自己__declspec(align(#))

    欲瞭解更多信息,請參閱:GCC vs MSVC class packing and alignment


    多一點研究後到lemur_platform.h它看起來像中的代碼已經完成上述所有工作爲您服務!你會注意到#define LEMUR_POSTALIGN __attribute__ ((aligned))被封裝在#ifndef WIN32中。所以你需要做的是在你的Visual Studio項目中定義WIN32

    +0

    如果我沒有錯,我想win32是在Visual Studio項目中自動定義的。 還是有什麼特定的方式來定義win32? –

    +0

    @AsimSaeed我想你正在考慮'_WIN32',它是[總是定義](https://msdn.microsoft.com/en-us/library/b0084kay)。你需要定義'WIN32'。我建議使用預處理器參數,以便將它放在項目代碼而不是代碼中。爲此,請使用[\ D](https://msdn.microsoft.com/en-us/library/hhzbb5c8.aspx)指令。 –

    +0

    thanku @Jonathan。你的解決方案奏效 –

    相關問題