This feature is not supported on the Wolfram Cloud.

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

compiles a C source file.


  • To use CreateObjectFile, you first need to load it using Needs["CCompilerDriver`"].
  • 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 setting of $OperatingSystem.
  • The following options can be given:
  • "Compiler"Automaticthe compiler to use
    "CleanIntermediate"Automaticwhether temporary files should be deleted
    "CreateBinary"Truewhether the object file should be created
    "CompileOptions"""options to pass through to the compiler
    "CompilerInstallation"Automaticlocation of the compiler software
    "CompilerName"Automaticwhich compile command to use
    "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)
    "PreCompileCommands"""shell commands to run before compilation
    "PostCompileCommands"""shell commands to run after 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
    "WorkingDirectory"Automaticthe directory in which temporary files should be generated

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

First, load the package:

Click for copyable input

Define a C function called hypotenuse():

Click for copyable input

Compile the code to an object file:

Click for copyable input

Define a main() function that uses hypotenuse():

Click for copyable input

Compile the code for main() and include the object file containing hypotenuse():

Click for copyable input

Run the executable with and , and import its output:

Click for copyable input

Compare the results to those computed by the Wolfram Language:

Click for copyable input