DeclareCompiledComponent["name",decls]
コンパイル済みコンポーネント"name"に宣言 decls を加える.
DeclareCompiledComponent["name",fieldspec]
コンパイル済みコンポーネント"name"の指定されたフィールドに指定 spec を加える.
DeclareCompiledComponent
DeclareCompiledComponent["name",decls]
コンパイル済みコンポーネント"name"に宣言 decls を加える.
DeclareCompiledComponent["name",fieldspec]
コンパイル済みコンポーネント"name"の指定されたフィールドに指定 spec を加える.
詳細
- コンパイル済みコンポーネントを使ってコンパイル済み宣言の名前付きのグループを表すことができる.
- コンパイル済みコンポーネントを使って共有ライブラリに組み込むコンパイル済み機能を表すことができる.
- コンパイル済みコンポーネントはパクレットに埋め込むことができる.
- DeclareCompiledComponent["name",...]は,コンパイル済みコンポーネント"name"がすでに存在していなければこれを作成する.
- CreateCompilerEnvironmentおよびCompilerEnvironmentAppendToを使ってコンパイル済みコンポーネントからの宣言をコンパイラ環境に加えることができる.
- コンパイル済みコンポーネントからの宣言はインストールされた関数とライブラリ関数のビルドの際に使われる.
- インストールされた関数とライブラリ関数を含むライブラリはBuildCompiledComponentでビルドできる.
- インストールされた関数とライブラリ関数を含むライブラリはLoadCompiledComponentでロードできる.
- field の次の値を使うことができる.
-
"Declarations" コンポーネントで使う宣言 "InstalledFunctions" コンパイルする関数と結果をインストールするシンボル "LibraryFunctions" コンパイルする関数.LoadCompiledComponentで復元される "RawLibraryFunctions" ライブラリエキスポートとして利用可能なコンパイル関数 "LoadingEpilogs" LoadCompiledComponentがコンポーネントをロードした後で実行される関数 "ExternalLibraries" LoadCompiledComponentがコンポーネントをロードする前にロードされるライブラリ - "Declarations"は単一の宣言としてあるいは宣言のリストとして与えることができる.
- "InstalledFunctions"は,ビルドされたコンポーネントがロードされた際に func のコンパイル済みバージョンをシンボル sym にインストールするように指定する規則 symfunc として与えることができる."InstalledFunctions"は規則の連想も取る.
- "InstalledFunctions"はシンボル sym を与えることができる.このシンボルは,事実上,インストールされた関数 symsym を宣言する.sym が(コンポーネントで定義されたものを含む)コンパイル可能な関数の名前ならこれはコンパイルされ,コンパイル済みコードの外で使用できるようにシンボル sym にインストールされる.シンボルのリストを与えることもできる. »
- "LibraryFunctions"は func のコンパイル済みバージョンがLoadCompiledComponentの結果で"name"という名前で使えるように指定する規則"name"func として与えることができる."LibraryFunctions"は規則の連想も取る.
- "RawLibraryFunctions"の項目は,"name"Typed[funcName,ty]の形の規則として与えられる.これは,ty 型の funcName のコンパイル済みバージョンが,そのコンポーネントのためにビルドされたライブラリによってエキスポートされるように指示する.コンパイルにCompiledComponentRawInterfaceのコンポーネントが使われている場合,それらは funcName を直接参照できる.
- "LoadingEpilogs"は単一の関数または関数のリストとして与えることができる.
- "ExternalLibraries"は単一のライブラリ指定としてあるいはライブラリ指定のリストとして与えることができる.ライブラリ指定はFindLibraryで解決されなければならない.
- "InstalledFunctions"フィールドおよび"LibraryFunctions"フィールドはコンパイルされるソースを含んでいる.BuildCompiledComponentはそのソースをビルドして結果を動的ライブラリに保存する.動的ライブラリはLoadCompiledComponentでロードしてコンパイルの結果を復元できる.
- "RawLibraryFunctions"の名前は,動的ライブラリの形式によって制限される.
例題
すべて開く すべて閉じる例 (2)
宣言を含むコンパイル済みコンポーネント"demo" を作成する:
DeclareCompiledComponent["demo", FunctionDeclaration[square, Typed[{"Real64"} -> "Real64"]@Function[x, x ^ 2]]];CompiledComponent["demo"]FunctionCompileの呼出しに"demo" を使う:
comp = FunctionCompile[CompiledComponent["demo"], Function[Typed[arg, "Real64"], square[arg]]]comp[10]DeleteObject[CompiledComponent["demo"]]DeclareCompiledComponent["demo1", FunctionDeclaration[square, Typed[{"Real64"} -> "Real64"]@Function[{x}, x ^ 2]]];コンパイル済みコンポーネントオブジェクトはコンポーネントについての情報を返す:
CompiledComponent["demo1"]コンパイル済みコンポーネントオブジェクトは以下の特性を持つ:
CompiledComponent["demo1"]["Properties"]CompiledComponent["demo1"]["Declarations"]スコープ (5)
DeclareCompiledComponent["fullComponent", {
FunctionDeclaration[return12, Typed[{} -> "MachineInteger"]@Function[{}, 12]],
FunctionDeclaration[addtwo, Typed[{"MachineInteger"} -> "MachineInteger"]@Function[x, x + 2]]
}];DeclareCompiledComponent["fullComponent", "LibraryFunctions" -> <|
"libFunc" -> Function[Typed[arg, "Real64"], Sqrt[arg]]
|>];DeclareCompiledComponent["fullComponent", "InstalledFunctions" -> addtwo];CompiledComponent["fullComponent"][All]CompiledComponent["fullComponent"]["Properties"]CompiledComponent["fullComponent"]["Declarations"]DeleteObject[CompiledComponent["fullComponent"]]DeclareCompiledComponentはライブラリにコンパイルする関数を与えることができる:
DeclareCompiledComponent["libDemo", "LibraryFunctions" -> <|
"fun1" -> Function[{Typed[arg, "Real64"]}, arg ^ 2]
|>];BuildCompiledComponent["libDemo"]lib = LoadCompiledComponent["libDemo"]lib["LibraryFunctions"]["fun1"][10.5]DeclareCompiledComponentはシンボルを定義してインストールされたコードを取得することができる:
DeclareCompiledComponent["demoInstFunc", "InstalledFunctions" -> <|
square -> Function[Typed[arg, "Real64"], arg ^ 2]
|>];DeclareCompiledComponent["demoInstFunc", FunctionDeclaration[double, Typed[{"Real64"} -> "Real64"]@Function[arg, arg * 2]]];名前しか与えられない場合にコンパイラ内の定義を検索してインストールされた関数を追加する:
DeclareCompiledComponent["demoInstFunc", "InstalledFunctions" -> {
double
}];BuildCompiledComponent["demoInstFunc"]コンポーネントライブラリを,ライブラリ内のインストールされた関数を呼び出すことで自動的にロードする:
double[12.3]square[12.3]DeclareCompiledComponentは,インストールされたコードを取得するためのシンボルが定義できる:
DeclareCompiledComponent["demoInstFunc", "InstalledFunctions" -> <|
square -> Function[Typed[arg, "Real64"], arg ^ 2]
|>];DeclareCompiledComponent["demoInstFunc", FunctionDeclaration[double, Typed[{"Real64"} -> "Real64"]@Function[arg, arg * 2]]];名前だけを指定してインストールされた関数を追加し,コンパイラで定義を検索する:
DeclareCompiledComponent["demoInstFunc", "InstalledFunctions" -> {
double
}];BuildCompiledComponent["demoInstFunc"]コンポーネントライブラリのインストールされた関数を呼び出すことで,これを自動的にロードする:
double[12.3]square[12.3]DeclareCompiledComponentは,他のコンパイル済みコードで使用するための生のライブラリインターフェースを作成することができる:
DeclareCompiledComponent["demoLibrary", {
FunctionDeclaration[square, Typed[{"Real64"} -> "Real64"]@Function[arg, arg ^ 2]]
}
];
DeclareCompiledComponent["demoLibrary", "RawLibraryFunctions" -> <|
"square" -> Typed[square, {"Real64"} -> "Real64"]
|>];BuildCompiledComponent["demoLibrary"]LoadCompiledComponent["demoLibrary"]libDecl = LibraryFunctionDeclaration[square -> "square", "demoLibrary", {"Real64"} -> "Real64"];cf = FunctionCompile[{libDecl}, Function[{Typed[arg, "Real64"]}, square[arg]]]cf[5.6]LibraryFunctionDeclarationを使う代りに,コンポーネントの生のインターフェースを直接使うこともできる:
cf = FunctionCompile[CompiledComponentRawInterface["demoLibrary"], Function[{Typed[arg, "Real64"]}, square[arg]]]cf[5.6]コンポーネントからの宣言はライブラリを再度コンパイルすることなしに使えるので便利である.
"RawLibraryFunctions"で構築されたコンポーネントライブラリはForeignFunctionLoadで使うことができる:
fun = ForeignFunctionLoad["demoLibrary", "square", {"CDouble"} -> "CDouble"]fun[ 5.6]テクニカルノート
関連するガイド
テキスト
Wolfram Research (2022), DeclareCompiledComponent, Wolfram言語関数, https://reference.wolfram.com/language/ref/DeclareCompiledComponent.html.
CMS
Wolfram Language. 2022. "DeclareCompiledComponent." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DeclareCompiledComponent.html.
APA
Wolfram Language. (2022). DeclareCompiledComponent. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DeclareCompiledComponent.html
BibTeX
@misc{reference.wolfram_2026_declarecompiledcomponent, author="Wolfram Research", title="{DeclareCompiledComponent}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/DeclareCompiledComponent.html}", note=[Accessed: 13-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_declarecompiledcomponent, organization={Wolfram Research}, title={DeclareCompiledComponent}, year={2022}, url={https://reference.wolfram.com/language/ref/DeclareCompiledComponent.html}, note=[Accessed: 13-September-2026]}