CreateObjectFile[source,name]
Cコード文字列をコンパイルし,オブジェクトファイル name.ext を作成する.
CreateObjectFile[{file},name]
Cソースファイルをコンパイルし,オブジェクトファイル name.ext を作成する.
CreateObjectFile
CreateObjectFile[source,name]
Cコード文字列をコンパイルし,オブジェクトファイル name.ext を作成する.
CreateObjectFile[{file},name]
Cソースファイルをコンパイルし,オブジェクトファイル name.ext を作成する.
詳細とオプション
- CreateObjectFileを使うにはまずNeeds["CCompilerDriver`"]でCCompilerDriverパッケージをロードしなければならない.
- source が文字列の場合, CreateObjectFileはそれをCコードとして扱う.source が1つまたは複数の文字列のリストの場合は,Cコードを含むファイルのリストとして扱う.
- CreateObjectFileはCコンパイラを見付けることができないときは,メッセージを生成し,$Failedを返す.
- オブジェクトファイルに与えられる拡張子は,それが作成されたプラットフォームに依存する.
- 以下のオプションが使える:
-
"CleanIntermediate" Automatic 一時ファイルを削除するかどうか "CompileOptions" "" コンパイラに渡すオプション "Compiler" Automatic 使用するコンパイラ "CompilerInstallation" Automatic コンパイラソフトウェアの場所 "CompilerName" Automatic どのコンパイルコマンドを使うか "CreateBinary" True オブジェクトファイルを作るかどうか "Debug" False デバッグ情報を使ってコンパイルし,中間出力は削除せず,コンパイルコマンドと出力を表示する "Defines" {} ビルドで使用するCプリプロセッサの定義 "IncludeDirectories" {} includeパスに加えるディレクトリ "Language" Automatic ソースコードの言語(自動検出を利用するのではなく,ソースがCまたはC++であることを前提とするのに使うことができる) "PostCompileCommands" "" コンパイルの後に実行するシェルコマンド "PreCompileCommands" "" コンパイルの前に実行するシェルコマンド "ShellCommandFunction" None コンパイルで使用するシェルコマンドで呼び出す関数 "ShellOutputFunction" None コンパイルコマンドの実行によるシェル出力で呼び出す関数 "SystemCompileOptions" {} "CompileOptions"の前にコンパイラに渡すオプション "SystemIncludeDirectories" Automatic Wolfram言語ヘッダファイルを置くディレクトリ "TargetDirectory" Automatic 実行ファイルが作られるディレクトリ "TargetSystemID" $SystemID どのシステム用の出力を生成するか "TransferProtocolLibrary" Automatic 使用するリンクライブラリ(WSTPまたはMathLink) "WorkingDirectory" Automatic 一時ファイルを生成するためのディレクトリ
例題
例 (1)
Needs["CCompilerDriver`"]C関数を定義し,それをオブジェクトファイルにコンパイルする:
hypotSrc = StringJoin[
"#include <math.h>
",
"double hypotenuse(double x, double y)
",
"{
",
" return sqrt(x*x + y*y);
",
"}
"];
hypotObj = CreateObjectFile[hypotSrc, "hypotenuse"]オブジェクトファイルを使用するmainを持つファイルをインクルードし、それらすべてを実行可能ファイルにコンパイルする:
hypotMainSrc = StringJoin[
"#include <stdio.h>
",
"#include <stdlib.h>
",
"double hypotenuse(double x, double y);
",
"
",
"int main(int argc, char** argv)
",
"{
",
" double x, y, h;
",
" x = argc < 2? 1.0 : atof(argv[1]);
",
" y = argc < 3? 1.0 : atof(argv[2]);
",
" h = hypotenuse(x, y);
",
" printf(\"%f\
\", h);
",
"}
"];
hypotExe = CreateExecutable[hypotMainSrc, "hypotenuse", "ExtraObjectFiles" -> {hypotObj}]Import["!" <> hypotExe <> " 2 5", "Text"]Sqrt[2.0 ^ 2 + 5.0 ^ 2]テクニカルノート
関連するガイド
テキスト
Wolfram Research (2010), CreateObjectFile, Wolfram言語関数, https://reference.wolfram.com/language/CCompilerDriver/ref/CreateObjectFile.html.
CMS
Wolfram Language. 2010. "CreateObjectFile." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/CCompilerDriver/ref/CreateObjectFile.html.
APA
Wolfram Language. (2010). CreateObjectFile. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/CCompilerDriver/ref/CreateObjectFile.html
BibTeX
@misc{reference.wolfram_2026_createobjectfile, author="Wolfram Research", title="{CreateObjectFile}", year="2010", howpublished="\url{https://reference.wolfram.com/language/CCompilerDriver/ref/CreateObjectFile.html}", note=[Accessed: 07-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_createobjectfile, organization={Wolfram Research}, title={CreateObjectFile}, year={2010}, url={https://reference.wolfram.com/language/CCompilerDriver/ref/CreateObjectFile.html}, note=[Accessed: 07-August-2026]}