Creating an Object File

The CCompilerDriver package lets you work with C compilers that are installed on your computer. It is used automatically by the Mathematica compiler when you set the option CompilationTarget to "C", but you can use it to build your own executables, libraries, and object files from source code written in the C language.

This section discusses some of the ways that you can use these tools to create object files. The main function to create a library is CreateObjectFile. These examples will use SymbolicC.

First, the packages are loaded.

In[1]:=
Click for copyable input

This creates a basic C function.

In[4]:=
Click for copyable input
Out[5]=

This compiles the code into an object file.

In[6]:=
Click for copyable input
Out[6]=

If the input came from one or more files of C code, these could be given to CreateObjectFile in a list.

The extension for the generated object file is added to be compatible with the system.

CreateObjectFile lets you compile different source files with different settings.

More information on options and settings is found in the section on Configuring the Compilation.

New to Mathematica? Find your learning path »
Have a question? Ask support »