CCompilerDriver`
CCompilerDriver`

CreateObjectFile

CreateObjectFile[source,name]

compiles a string of C code and creates an object file, name.ext.

CreateObjectFile[{file},name]

compiles a C source file and creates an object file, name.ext.

Details and Options

  • To use CreateObjectFile, you first need to load the CCompilerDriver package using Needs["CCompilerDriver`"].
  • If source is a string, CreateObjectFile treats it as C code. If source is a list of one or more strings, it treats it as a list of files that contain C code.
  • If CreateObjectFile cannot find a suitable C compiler, it issues a message and returns $Failed.
  • The extension given to the object file depends on the platform on which it is created.
  • The following options can be given:
  • "CleanIntermediate"Automaticwhether temporary files should be deleted
    "CompileOptions"""options to pass through to the compiler
    "Compiler"Automaticthe compiler to use
    "CompilerInstallation"Automaticlocation of the compiler software
    "CompilerName"Automaticwhich compile command to use
    "CreateBinary"Truewhether the object file should be created
    "Debug"Falsecompiles with debug information, does not clean the intermediate output, and prints the compile commands and output
    "Defines"{}C preprocessor defines to use for the build
    "IncludeDirectories"{}directories to add to the include path
    "Language"Automaticwhat language the source code is in (can be used to assume source is C or C++ rather than relying on automatic detection)
    "PostCompileCommands"""shell commands to run after compilation
    "PreCompileCommands"""shell commands to run before compilation
    "ShellCommandFunction"Nonefunction to call with the shell commands used for compilation
    "ShellOutputFunction"Nonefunction to call with the shell output of running the compilation commands
    "SystemCompileOptions"{}options to pass through to the compiler before "CompileOptions"
    "SystemIncludeDirectories"Automaticdirectories to locate Wolfram Language header files
    "TargetDirectory"Automaticthe directory in which the executable file should be created
    "TargetSystemID"$SystemIDthe system for which output should be generated
    "TransferProtocolLibrary"Automaticwhich link library (WSTP or MathLink) to use
    "WorkingDirectory"Automaticthe directory in which temporary files should be generated

Examples

Basic Examples  (1)

Load the CCompilerDriver package:

Define a C function and compile it to an object file:

Include the object file with a main that uses it and compile it all into an executable:

Run the executable with and :

Compare the results to those computed by the Wolfram Language:

Wolfram Research (2010), CreateObjectFile, Wolfram Language function, https://reference.wolfram.com/language/CCompilerDriver/ref/CreateObjectFile.html.

Text

Wolfram Research (2010), CreateObjectFile, Wolfram Language function, 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_2024_createobjectfile, author="Wolfram Research", title="{CreateObjectFile}", year="2010", howpublished="\url{https://reference.wolfram.com/language/CCompilerDriver/ref/CreateObjectFile.html}", note=[Accessed: 05-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_createobjectfile, organization={Wolfram Research}, title={CreateObjectFile}, year={2010}, url={https://reference.wolfram.com/language/CCompilerDriver/ref/CreateObjectFile.html}, note=[Accessed: 05-November-2024 ]}