CCompilerDriver`
CCompilerDriver`

CreateExecutable

CreateExecutable[source,name]

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

CreateExecutable[{file1,},name]

compiles a number of C and mprep source files and creates an executable file, name.ext.

Details and Options

  • To use CreateExecutable, you first need to load it using Needs["CCompilerDriver`"].
  • If source is a string, CreateExecutable 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 CreateExecutable cannot find a suitable C compiler, it issues a message and returns $Failed.
  • The extension given to the library depends on the platform for which the executable is created.
  • If an input file has the extension .tm, CreateExecutable will treat it as a Wolfram Symbolic Transfer Protocol (WSTP) template file and use mprep to process it.
  • The following options can be given:
  • "Compiler"Automaticthe compiler to use
    "CleanIntermediate"Automaticwhether temporary files should be deleted
    "CreateBinary"Truewhether the executable 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
    "ExtraObjectFiles"{}previously compiled object files to include in the executable
    "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)
    "Libraries"{}libraries to use to build the executable
    "LibraryDirectories"{}directories to add to the library lookup path
    "LinkerOptions"{}options passed to the linker
    "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
    "SystemLibraries"AutomaticWolfram Language libraries
    "SystemLibraryDirectories"Automaticdirectories to locate Wolfram Language libraries
    "SystemLinkerOptions"{}options passed to the linker before "LinkerOptions"
    "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)

First, load the package:

This creates an executable:

This runs the executable:

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

Text

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

CMS

Wolfram Language. 2010. "CreateExecutable." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/CCompilerDriver/ref/CreateExecutable.html.

APA

Wolfram Language. (2010). CreateExecutable. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/CCompilerDriver/ref/CreateExecutable.html

BibTeX

@misc{reference.wolfram_2024_createexecutable, author="Wolfram Research", title="{CreateExecutable}", year="2010", howpublished="\url{https://reference.wolfram.com/language/CCompilerDriver/ref/CreateExecutable.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

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