Introduction

The CCompilerDriver package lets you work with C compilers that are installed on your computer. It lets you build executables, libraries, and object files from C source code. It is called automatically by the Mathematica compiler when you set the option CompilationTarget to "C". It is also useful for building MathLink executables as well as Wolfram Libraries (dynamic linking libraries that can be linked into Mathematica).

To use the package it must first be loaded.

In[1]:=
Click for copyable input

This is a sample source file for a Wolfram Library.

In[2]:=
Click for copyable input

This creates a library and returns the full path.

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

If you do not have any suitable C compiler, the compilation will fail and a message will be generated.

This library was written as a Wolfram Library, so you can load functions from it using LibraryFunctionLoad.

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

This calls the LibraryFunction.

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

In addition to building libraries, the CCompilerDriver package lets you build executables and object files.

Does Mathematica Include a C Compiler?

Mathematica does not ship with a C compiler. If you want to take advantage of the CCompilerDriver package, you will have to make sure that you have an installed C compiler on your computer. Many computers either ship with a C compiler or can add one as an optional extra. In addition, you can find other compilers from various commercial and non-commercial sources.

You can learn about the C compilers that are supported in the section on specific compilers.

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