編譯器物件 (compiler)

此物件由 meson.get_compiler() 傳回。它代表特定語言的編譯器,並允許您查詢其屬性。

由以下項目傳回

編譯器物件是由下列函式和方法傳回

注意

這些編譯器檢查不會使用透過 add_*_arguments()、命令列上的 -Dlang_args 或環境中的 CFLAGS/LDFLAGS 等新增的編譯器引數。因此,您可以相信測試將是完全獨立的,並且不會因為建構檔案的其他部分或使用者新增的自訂旗標而失敗。

注意

請注意,如果您有一個包含所有相依性的單一前置詞,您可能會發現更容易將環境變數 C_INCLUDE_PATH 與 GCC/Clang 和 INCLUDE 與 MSVC 附加,以擴展預設的包含路徑,並將 LIBRARY_PATH 與 GCC/Clang 和 LIB 與 MSVC 附加,以擴展預設的程式庫搜尋路徑。

但是,使用 GCC 時,交叉編譯時會忽略這些變數。在這種情況下,您需要使用規格檔案。請參閱:http://www.mingw.org/wiki/SpecsFileHOWTO

編譯器物件方法

compiler.alignment()

傳回指定類型的對齊方式。對於類似 C 的語言,對於類似 C 的語言,標頭 stddef.hstdio.h 會在原生編譯時隱式包含,只有 stddef.h 在交叉編譯時才會包含。

簽名

# Returns the alignment of the specified type
int alignment(
  str typename,     # The name of the type to check

  # Keyword arguments:
  args         : list[str]        # Used to pass a list of compiler arguments
  dependencies : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  prefix       : str | list[str]  # Used to add `#include`s and other things that are required
)

引數

compiler.alignment() 方法接受下列位置引數

名稱 類型 描述 標籤
typename str

要檢查的類型名稱。

最後,compiler.alignment() 接受下列關鍵字引數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。


compiler.check_header()

如果指定的標頭在指定的字首、相依性和引數下可用,則傳回 true。

簽名

(自 0.47.0 起)

# Returns true if the specified header is *usable*
bool check_header(
  str header_name,     # The header to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
  required            : bool | feature   # When set to `true`, Meson will halt if the header check fails
)

引數

compiler.check_header() 方法接受下列位置引數

名稱 類型 描述 標籤
header_name str

要檢查的標頭。

最後,compiler.check_header() 接受下列關鍵字引數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。

required bool | feature

設定為 true 時,如果標頭檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 0.50.0 起)

預設值 = false


compiler.cmd_array()

傳回包含編譯器命令的陣列。

簽名

list[str] cmd_array()


compiler.compiles()

如果程式碼已編譯,則傳回 true。

簽名

# Returns true if the code compiles
bool compiles(
  str | file code,     # The source code to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  name                : str              # The name to use for printing a message about the compiler check
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  required            : bool | feature   # When set to `true`, Meson will halt if the check fails
  werror              : bool             # When set to `true`, compiler warnings are treated as error
)

引數

compiler.compiles() 方法接受下列位置引數

名稱 類型 描述 標籤
code str | file

要檢查的原始碼。

如果傳遞字串,則會直接使用程式碼。如果傳遞 file 物件,則其內容會用於編譯器檢查。

最後,compiler.compiles() 接受下列關鍵字引數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

name str

用於列印有關編譯器檢查訊息的名稱。如果未傳遞此關鍵字引數,則不會列印有關檢查的訊息。

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

required bool | feature

設定為 true 時,如果檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 1.5.0 起)

預設值 = false

werror bool

設定為 true 時,編譯器警告會被視為錯誤。

(自 1.3.0 起)

預設值 = false


compiler.compute_int()

計算給定運算式的值 (例如 1 + 2)。當進行交叉編譯時,會使用迭代演算法進行評估,您可以指定關鍵字引數 low (預設為 -1024)、high (預設為 1024) 和 guess 來指定搜尋的最大值和最小值以及首先嘗試的值。對於類似 C 的語言,標頭 stddef.hstdio.h 會在原生編譯時隱式包含,只有 stddef.h 在交叉編譯時才會包含。

簽名

(自 0.40.0 起)

# Computes the value of the given expression
int compute_int(
  str expr,     # The expression to compute

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  guess               : int              # The value to try first
  high                : int              # The max value
  include_directories : inc | list[inc]  # Extra directories for header searches
  low                 : int              # The min value
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
)

引數

compiler.compute_int() 方法接受下列位置引數

名稱 類型 描述 標籤
expr str

要計算的運算式。

最後,compiler.compute_int() 接受下列關鍵字引數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

guess int

首先嘗試的值。

high int

最大值。

預設值 = 1024

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

low int

最小值。

預設值 = -1024

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。


compiler.find_library()

嘗試尋找位置引數中指定的程式庫。

簽名

# Tries to find the library specified in the positional argument
dep find_library(
  str libname,     # The library to find

  # Keyword arguments:
  dirs                       : list[str]        # Additional directories to search in
  disabler                   : bool             # If `true`, this method will return a disabler on a failed check.
  has_headers                : list[str]        # List of headers that must be found as well
  header_args                : list[str]        # When the `has_headers` kwarg is also used, this argument is passed to
  header_dependencies        : dep | list[dep]  # When the `has_headers` kwarg is also used, this argument is passed to
  header_include_directories : inc | list[inc]  # When the `has_headers` kwarg is also used, this argument is passed to
  header_no_builtin_args     : bool             # When the `has_headers` kwarg is also used, this argument is passed to
  header_prefix              : str              # When the `has_headers` kwarg is also used, this argument is passed to
  required                   : bool | feature   # If set `true`, Meson will abort with an error if the library could not
  static                     : bool             # If `true`, the search is limited to static libraries only
)

引數

compiler.find_library() 方法接受下列位置引數

名稱 類型 描述 標籤
libname str

要尋找的程式庫。

最後,compiler.find_library() 接受下列關鍵字引數

名稱 類型 描述 標籤
dirs list[str]

要搜尋的其他目錄。

預設情況下,程式庫會在系統程式庫目錄 (例如 /usr/lib) 中搜尋。在此處指定更多目錄會導致 Meson 在這些目錄以及系統目錄中搜尋。

disabler bool

如果為 true,此方法會在檢查失敗時傳回 disabler

(自 0.49.0 起)

預設值 = false

has_headers list[str]

也必須找到的標頭清單。此檢查相當於使用 compiler.has_header() 呼叫檢查每個標頭。

使用時,compiler.has_header() 將接受的 kwargs 可在此處傳遞,並加上 header_ 前置詞,且對標頭檢查的效果相同。

(自 0.50.0 起)

header_args list[str]

當也使用 has_headers kwarg 時,此引數會以 args 的形式傳遞至 compiler.has_header()

(自 0.51.0 起)

header_dependencies dep | list[dep]

當也使用 has_headers kwarg 時,此引數會以 dependencies 的形式傳遞至 compiler.has_header()

(自 0.51.0 起)

header_include_directories inc | list[inc]

當也使用 has_headers kwarg 時,此引數會以 include_directories 的形式傳遞至 compiler.has_header()

(自 0.51.0 起)

header_no_builtin_args bool

當也使用 has_headers kwarg 時,此引數會以 no_builtin_args 的形式傳遞至 compiler.has_header()

(自 0.51.0 起)

預設值 = false

header_prefix str

當也使用 has_headers kwarg 時,此引數會以 prefix 的形式傳遞至 compiler.has_header()

(自 0.51.0 起)

required bool | feature

如果設定為 true,如果找不到程式庫,Meson 會中止並發生錯誤。否則,Meson 將繼續執行,且傳回物件的 found 方法將傳回 false

設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 0.47.0 起) 也可以在此處傳遞 feature 選項的值。

預設值 = true

static bool

如果為 true,搜尋僅限於靜態程式庫。將此值設定為 false (預設值) 會搜尋共享靜態程式庫。

(自 0.51.0 起)

預設值 = false


compiler.first_supported_argument()

給定字串清單,傳回包含通過 compiler.has_argument() 測試的第一個引數的單一元素清單,如果沒有通過測試,則傳回空陣列。

簽名

(自 0.43.0 起)

# Given a list of strings, returns a single-element list containing the first
list[str] first_supported_argument(
  str arg...,  # The arguments to check
)

引數

此方法接受 0無限 個可變引數 (arg...),類型為 str

要檢查的引數。


給定字串清單,傳回通過 compiler.has_link_argument() 測試的第一個引數,如果沒有通過測試,則傳回空陣列。

簽名

(自 0.46.0 起)

# Given a list of strings, returns the first argument that passes the
list[str] first_supported_link_argument(
  str arg...,  # The link arguments to check
)

引數

此方法接受 0無限 個可變引數 (arg...),類型為 str

要檢查的連結引數。


compiler.get_argument_syntax()

傳回一個字串,識別編譯器採用的引數類型。可以是 gccmsvc 或未定義的字串值。此方法可用於識別不是 gcc 或 msvc,但使用與 clang 或 icc 等這兩個編譯器之一相同的引數語法的編譯器,尤其是在不同作業系統上使用不同語法時。

簽名

(自 0.49.0 起)

str get_argument_syntax()


compiler.get_define()

以字串形式傳回給定的前處理器符號的值,如果未定義則傳回空字串。

(自 0.47.0 版本起) 此方法會如同編譯器般串連字串字面值。例如,"a" "b" 會變成 "ab"

簽名

(自 0.40.0 起)

# Returns the given preprocessor symbol's value
str get_define(
  str definename,     # The define to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
)

引數

方法 compiler.get_define() 接受以下位置參數

名稱 類型 描述 標籤
definename str

要檢查的 define。

最後,compiler.get_define() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。


compiler.get_id()

傳回一個字串,識別編譯器。例如,gccmsvc以及更多

簽名

str get_id()


compiler.get_linker_id()

傳回一個字串,識別連結器。例如,ld.bfdlink以及更多

簽名

(自 0.53.0 版本起)

str get_linker_id()


compiler.get_supported_arguments()

傳回一個陣列,其中僅包含編譯器支援的參數,如同個別對它們呼叫 compiler.has_argument() 一樣。

簽名

(自 0.43.0 起)

# Returns an array containing only the arguments supported by the compiler,
list[str] get_supported_arguments(
  str arg...,  # The arguments to check

  # Keyword arguments:
  checked : str  # Supported values:
)

引數

此方法接受 0無限 個可變引數 (arg...),類型為 str

要檢查的引數。

方法 compiler.get_supported_arguments() 接受以下關鍵字參數

名稱 類型 描述 標籤
checked str

支援的值

  • 'off':靜默忽略不支援的參數
  • 'warn':針對不支援的參數印出警告
  • 'require':如果至少有一個參數不支援,則中止

(自 0.59.0 版本起)

預設值 = 'off'


compiler.get_supported_function_attributes()

傳回一個陣列,其中包含任何支援的 GCC 風格屬性名稱。等同於個別對它們呼叫 compiler.has_function_attribute()

簽名

(自 0.48.0 版本起)

list[str] get_supported_function_attributes()


傳回一個陣列,其中僅包含編譯器支援的參數,如同個別對它們呼叫 compiler.has_link_argument() 一樣。

簽名

(自 0.46.0 起)

# Returns an array containing only the arguments supported by the compiler,
list[str] get_supported_link_arguments(
  str arg...,  # The link arguments to check
)

引數

此方法接受 0無限 個可變引數 (arg...),類型為 str

要檢查的連結引數。


compiler.has_argument()

如果編譯器接受指定的命令列參數,亦即,可以編譯程式碼而不會發生錯誤或印出關於未知旗標的警告,則傳回 true

簽名

# Returns `true` if the compiler accepts the specified command line argument,
bool has_argument(
  str argument,     # The argument to check

  # Keyword arguments:
  required : bool | feature  # When set to `true`, Meson will halt if the check fails
)

引數

方法 compiler.has_argument() 接受以下位置參數

名稱 類型 描述 標籤
argument str

要檢查的參數。

最後,compiler.has_argument() 接受以下關鍵字參數

名稱 類型 描述 標籤
required bool | feature

設定為 true 時,如果檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 1.3.0 起)

預設值 = false


compiler.has_define()

如果給定的前置處理器符號已定義,則傳回 true。

簽名

(自 1.3.0 起)

# Returns true if the given preprocessor symbol is *defined*
bool has_define(
  str definename,     # The define to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
)

引數

方法 compiler.has_define() 接受以下位置參數

名稱 類型 描述 標籤
definename str

要檢查的 define。

最後,compiler.has_define() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。


compiler.has_function()

如果標準函式庫或以 args 關鍵字傳入的函式庫提供了給定的函式,則傳回 true。

簽名

# Returns true if the given function is provided
bool has_function(
  str funcname,     # The function to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
  required            : bool | feature   # When set to `true`, Meson will halt if the check fails
)

引數

方法 compiler.has_function() 接受以下位置參數

名稱 類型 描述 標籤
funcname str

要檢查的函式。

最後,compiler.has_function() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。

required bool | feature

設定為 true 時,如果檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 1.3.0 起)

預設值 = false


compiler.has_function_attribute()

如果編譯器支援 GNU 風格 (__attribute__(...)) 的 name,則傳回 true。這比手動編譯檢查更佳,因為它可能會針對不支援此類屬性的編譯器進行最佳化。此表格列出所有支援的屬性。

簽名

(自 0.48.0 版本起)

# Returns `true` if the compiler supports the GNU style (`__attribute__(
bool has_function_attribute(
  str name,     # The attribute name to check

  # Keyword arguments:
  required : bool | feature  # When set to `true`, Meson will halt if the check fails
)

引數

方法 compiler.has_function_attribute() 接受以下位置參數

名稱 類型 描述 標籤
name str

要檢查的屬性名稱。

最後,compiler.has_function_attribute() 接受以下關鍵字參數

名稱 類型 描述 標籤
required bool | feature

設定為 true 時,如果檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 1.3.0 起)

預設值 = false


compiler.has_header()

如果指定的標頭存在且具有指定的前置詞、相依性和參數,則傳回 true。

此方法比 compiler.check_header() 更快,因為它僅執行前置處理器檢查。

簽名

# Returns true if the specified header is *exists*
bool has_header(
  str header_name,     # The header to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
  required            : bool | feature   # When set to `true`, Meson will halt if the header check fails
)

引數

方法 compiler.has_header() 接受以下位置參數

名稱 類型 描述 標籤
header_name str

要檢查的標頭。

最後,compiler.has_header() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。

required bool | feature

設定為 true 時,如果標頭檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 0.50.0 起)

預設值 = false


compiler.has_header_symbol()

偵測指定的標頭中是否宣告了特定的符號。

此處的符號包括函式、變數、#define、型別定義等。

簽名

# Detects whether a particular symbol is declared in the specified header
bool has_header_symbol(
  str header,     # The header to check
  str symbol,     # The symbol to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
  required            : bool | feature   # When set to `true`, Meson will halt if the header check fails
)

引數

方法 compiler.has_header_symbol() 接受以下位置參數

名稱 類型 描述 標籤
header str

要檢查的標頭。

symbol str

要檢查的符號。

最後,compiler.has_header_symbol() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。

required bool | feature

設定為 true 時,如果標頭檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 0.50.0 起)

預設值 = false


如果連結器接受指定的命令列參數,亦即,可以編譯和連結程式碼而不會發生錯誤或印出關於未知旗標的警告,則傳回 true。連結參數將會傳遞給編譯器,因此通常應該具有 -Wl, 前置詞。在 VisualStudio 上,將會預先加上 /link 參數。

簽名

(自 0.46.0 起)

# Returns `true` if the linker accepts the specified command line argument,
bool has_link_argument(
  str argument,     # The argument to check

  # Keyword arguments:
  required : bool | feature  # When set to `true`, Meson will halt if the check fails
)

引數

方法 compiler.has_link_argument() 接受以下位置參數

名稱 類型 描述 標籤

最後,compiler.has_link_argument() 接受以下關鍵字參數

名稱 類型 描述 標籤


compiler.has_member()

如果型別具有指定的成員,則傳回 true。

簽名

# Returns true if the type has the specified member
bool has_member(
  str typename,       # The type to check
  str membername,     # The member to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
  required            : bool | feature   # When set to `true`, Meson will halt if the check fails
)

引數

方法 compiler.has_member() 接受以下位置參數

名稱 類型 描述 標籤
typename str

要檢查的型別。

membername str

要檢查的成員。

最後,compiler.has_member() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。

required bool | feature

設定為 true 時,如果檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 1.3.0 起)

預設值 = false


compiler.has_members()

如果型別具有所有指定的成員,則傳回 true

簽名

# Returns `true` if the type has *all* the specified members
bool has_members(
  str typename,     # The type to check
  str member...,    # The members to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
  required            : bool | feature   # When set to `true`, Meson will halt if the check fails
)

引數

方法 compiler.has_members() 接受以下位置參數

名稱 類型 描述 標籤
typename str

要檢查的型別。

此外,此方法接受 1 個到 infinity 個可變參數 (member...),其類型為 str

要檢查的成員

最後,compiler.has_members() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。

required bool | feature

設定為 true 時,如果檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 1.3.0 起)

預設值 = false


compiler.has_multi_arguments()

compiler.has_argument() 相同,但接受多個參數並在單次編譯器調用中使用它們。

簽名

(自 0.37.0 版本起)

# the same as compiler.has_argument() but takes multiple arguments
bool has_multi_arguments(
  str arg...,  # The arguments to check

  # Keyword arguments:
  required : bool | feature  # When set to `true`, Meson will halt if the check fails
)

引數

此方法接受 0無限 個可變引數 (arg...),類型為 str

要檢查的引數。

方法 compiler.has_multi_arguments() 接受以下關鍵字參數

名稱 類型 描述 標籤
required bool | feature

設定為 true 時,如果檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 1.3.0 起)

預設值 = false


compiler.has_link_argument() 相同,但接受多個參數並在單次編譯器調用中使用它們。

簽名

(自 0.46.0 起)

# the same as compiler.has_link_argument() but takes multiple arguments
bool has_multi_link_arguments(
  str arg...,  # The link arguments to check

  # Keyword arguments:
  required : bool | feature  # When set to `true`, Meson will halt if the check fails
)

引數

此方法接受 0無限 個可變引數 (arg...),類型為 str

要檢查的連結引數。

方法 compiler.has_multi_link_arguments() 接受以下關鍵字參數

名稱 類型 描述 標籤


compiler.has_type()

如果指定的權杖是型別,則傳回 true

簽名

# Returns `true` if the specified token is a type
bool has_type(
  str typename,     # The type to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
  required            : bool | feature   # When set to `true`, Meson will halt if the check fails
)

引數

方法 compiler.has_type() 接受以下位置參數

名稱 類型 描述 標籤
typename str

要檢查的型別。

最後,compiler.has_type() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。

required bool | feature

設定為 true 時,如果檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 1.3.0 起)

預設值 = false


如果程式碼可以編譯和連結,則傳回 true。

自 0.60.0 版本起,如果 file 物件的後綴與編譯器物件的語言不符,則會使用與後綴相對應的編譯器來編譯來源,而 links 方法的目標則會用於連結產生的物件檔案。

簽名

# Returns true if the code compiles and links
bool links(
  str | file code,     # The source code to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  name                : str              # The name to use for printing a message about the compiler check
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  required            : bool | feature   # When set to `true`, Meson will halt if the check fails
  werror              : bool             # When set to `true`, compiler warnings are treated as error
)

引數

方法 compiler.links() 接受以下位置參數

名稱 類型 描述 標籤

最後,compiler.links() 接受以下關鍵字參數

名稱 類型 描述 標籤


compiler.preprocess()

預先處理來源檔案列表,但不編譯它們。前置處理器將會收到與正常編譯相同的參數 (包含目錄、定義等)。這包括使用 add_project_arguments() 或在命令列中使用 -Dc_args=-DFOO 加入的參數。

簽名

(自 0.64.0 版本起)

# Preprocess a list of source files but do not compile them
list[custom_idx] preprocess(
  str | file | custom_tgt | custom_idx | generated_list source...,  # Input source to preprocess

  # Keyword arguments:
  compile_args        : list[str]                     # Extra flags to pass to the preprocessor
  dependencies        : dep | list[dep]               # Additionally dependencies required
  depends             : list[build_tgt | custom_tgt]  # Specifies that this target depends on the specified
  include_directories : inc | list[inc]               # Extra directories for header searches
  output              : str                           # Template for name of preprocessed files: `@PLAINNAME@` is replaced by
)

引數

此方法接受 0infinity 個可變參數 (source...),其類型為 str | file | custom_tgt | custom_idx | generated_list

要預先處理的輸入來源。支援以下類型

  • 相對於目前來源目錄的字串

  • 在任何先前建置檔案中定義的 file 物件

  • 設定時間產生器 (例如 configure_file()) 的傳回值

  • 建置時間產生器 (例如 custom_target()generator.process()) 的傳回值

    方法 compiler.preprocess() 接受以下關鍵字參數

    名稱 類型 描述 標籤
    compile_args list[str]

    要傳遞給前置處理器的額外旗標

    dependencies dep | list[dep]

    額外要求的相依性。

    (自 1.1.0 版本起)

    depends list[build_tgt | custom_tgt]

    指定此目標相依於指定的目標。這些目標應該在開始預先處理輸入之前建置。

    (自 1.4.0 版本起)

    include_directories inc | list[inc]

    額外的標頭搜尋目錄。

    (自 0.38.0 起)

    output str

    預先處理檔案名稱的範本:@PLAINNAME@ 會替換為來源檔案名稱,而 @BASENAME@ 會替換為不含副檔名的來源檔案名稱。


compiler.run()

嘗試編譯並執行給定的程式碼片段。

簽名

# Attempts to compile and execute the given code fragment
runresult run(
  str | file code,     # The source code to check

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  name                : str              # The name to use for printing a message about the compiler check
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  required            : bool | feature   # When set to `true`, Meson will halt if the check fails
  werror              : bool             # When set to `true`, compiler warnings are treated as error
)

引數

方法 compiler.run() 接受以下位置參數

名稱 類型 描述 標籤
code str | file

要檢查的原始碼。

如果傳遞字串,則會直接使用程式碼。如果傳遞 file 物件,則其內容會用於編譯器檢查。

最後,compiler.run() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

name str

用於列印有關編譯器檢查訊息的名稱。如果未傳遞此關鍵字引數,則不會列印有關檢查的訊息。

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

required bool | feature

設定為 true 時,如果檢查失敗,Meson 將會停止。設定為 feature 選項時,此功能將控制是否搜尋以及在找不到時是否失敗。

(自 1.5.0 起)

預設值 = false

werror bool

設定為 true 時,編譯器警告會被視為錯誤。

(自 1.3.0 起)

預設值 = false


compiler.sizeof()

傳回給定型別 (例如 'int') 的大小,如果型別未知,則傳回 -1。對於類似 C 的語言,會隱式包含標頭 stddef.hstdio.h 以進行原生編譯,而交叉編譯時只會包含 stddef.h

簽名

# returns the size of the given type (e
int sizeof(
  str typename,     # The type to compute

  # Keyword arguments:
  args                : list[str]        # Used to pass a list of compiler arguments
  dependencies        : dep | list[dep]  # Additionally dependencies required for compiling and / or linking
  include_directories : inc | list[inc]  # Extra directories for header searches
  no_builtin_args     : bool             # When set to `true`, the compiler arguments controlled by built-in configuration options are not added
  prefix              : str | list[str]  # Used to add `#include`s and other things that are required
)

引數

方法 compiler.sizeof() 接受以下位置參數

名稱 類型 描述 標籤
typename str

要計算的型別。

最後,compiler.sizeof() 接受以下關鍵字參數

名稱 類型 描述 標籤
args list[str]

用於傳遞編譯器引數的清單。通常支援為不在預設包含路徑中的標頭定義包含路徑,例如透過 -Isome/path/to/header,但不建議這樣做。

這是因為也可以透過 include_directoriesdependency kwarg (如果存在) 指定包含目錄。將要連結的程式庫與 -lfoo 傳遞的情況也是如此。

dependencies dep | list[dep]

編譯和/或連結所需的其他相依性。

include_directories inc | list[inc]

額外的標頭搜尋目錄。

(自 0.38.0 起)

no_builtin_args bool

設定為 true 時,不會新增由內建組態選項控制的編譯器引數。

預設值 = false

prefix str | list[str]

用於新增 #include 和宣告符號所需的其他項目。從 1.0.0 版本開始,也接受陣列。當傳遞陣列時,項目會以換行符號分隔連在一起。系統定義應透過編譯器引數傳遞 (例如:_GNU_SOURCE 通常在 Linux 上公開某些符號時需要,應透過 args 關鍵字引數傳遞)。


compiler.symbols_have_underscore_prefix()

如果 C 符號名稱修飾是以底線 (_) 作為符號的前綴,則傳回 true

簽名

(自 0.37.0 版本起)

bool symbols_have_underscore_prefix()


compiler.version()

以字串形式傳回編譯器的版本號碼。

簽名

str version()


搜尋結果為