當前位置:編程學習大全網 - 源碼下載 - Android 中 clang 是做什麽用的

Android 中 clang 是做什麽用的

最近在使用VS2015 Community, 在添加了shared items project, 並把源代碼加入shared items, 添加Android工程編譯的時候, 發現可以用Clang正常編譯(VS2015默認使用自帶的Clang編譯器來編譯安卓).壹開始並沒有多想, 後來在準備添加Clang支持的時候, 突然意識到, Blade並沒有做Clang編譯器的支持, 但是可以正常編譯! 最後發現, Clang也定義了__GNUC__, 編譯的時候就當做GCC編譯了,原因在於GCC只提供了extension檢查而沒其他定義可以區分編譯器。為了防止Clang編譯器需要特殊處理, 所以還是需要加上Clang支持, 所以Blade的代碼現在如下:1 #if defined(_MSC_VER) 2 # define BLADE_COMPILER BLADE_COMPILER_MSVC 3 #elif defined(__clang__) 4 //note: Clang also defines (__GNUC__), so we need detect Clang first, or it will be mistaken as GCC 5 # define BLADE_COMPILER BLADE_COMPILER_CLANG 6 # define BLADE_COMPILER_GNU_EXTENSION 1 7 #elif defined(__GNUC__) 8 # define BLADE_COMPILER BLADE_COMPILER_GNUC 9 # define BLADE_COMPILER_GNU_EXTENSION 110 #else11 # error Compiler not supported yet.12 # define BLADE_ALWAYS_INLINE inline13 #endif14 15 #if BLADE_COMPILER == BLADE_COMPILER_MSVC16 # define BLADE_ALIGNED(n) __declspec(align(n))17 # define BLADE_CDECL __cdecl18 # define BLADE_STDCALL __stdcall19 # define BLADE_FASTCALL __fastcall20 # define BLADE_FUNCTION __FUNCTION__21 # define BLADE_ALWAYS_INLINE __forceinline22 #elif BLADE_COMPILER_GNU_EXTENSION23 # define BLADE_ALIGNED(n) __attribute__((aligned(n)))24 # define BLADE_CDECL __attribute__((cdecl))25 # define BLADE_STDCALL __attribute__((stdcall))26 # define BLADE_FASTCALL __attribute__((fastcall))27 # define BLADE_FUNCTION __PRETTY_FUNCTION__28 # define BLADE_ALWAYS_INLINE __attribute__((always_inline))29 #else30 # error Compiler not supported yet.31 #endif對於支持GNU擴展的編譯器, 必須要在檢測GNU之前檢測, 否則會被誤認為GCC編譯器。也就是添加了CLANG編譯器, 但是對於支持GNU Extension的編譯器, 單獨有統壹的處理. 通常情況下, 只需要使用BLADE_COMPILER_GNU_EXTENSION就可以使用GCC和CLANG和其他支持GNU Extension的編譯器,除非真的要用到Clang的特性或者需要針對Clang進行特殊fix, 才會使用BLADE_COMPILER_CLANG。

  • 上一篇:hotdog數字收藏的中獎技巧hotdog如何提高中獎率?
  • 下一篇:求個簡單javascript代碼 謝謝,網站菜單功能
  • copyright 2024編程學習大全網