---
title: "FunctionCompileExportByteArray"
language: "en"
type: "Symbol"
summary: "FunctionCompileExportByteArray[fspec] gives a byte array of binary LLVM code obtained by compiling the function specification fspec. FunctionCompileExportByteArray[defs, fspec] uses the auxiliary definitions defs for compilation. FunctionCompileExportByteArray[fspec,  format] gives a byte array of binary code in the specified format."
canonical_url: "https://reference.wolfram.com/language/ref/FunctionCompileExportByteArray.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Code Compilation"
    link: "https://reference.wolfram.com/language/guide/CodeCompilation.en.md"
  - 
    title: "C/C++ Language Interface"
    link: "https://reference.wolfram.com/language/guide/CLanguageInterface.en.md"
related_functions: 
  - 
    title: "FunctionCompile"
    link: "https://reference.wolfram.com/language/ref/FunctionCompile.en.md"
  - 
    title: "FunctionCompileExport"
    link: "https://reference.wolfram.com/language/ref/FunctionCompileExport.en.md"
  - 
    title: "FunctionCompileExportString"
    link: "https://reference.wolfram.com/language/ref/FunctionCompileExportString.en.md"
  - 
    title: "FunctionCompileExportLibrary"
    link: "https://reference.wolfram.com/language/ref/FunctionCompileExportLibrary.en.md"
  - 
    title: "TargetSystem"
    link: "https://reference.wolfram.com/language/ref/TargetSystem.en.md"
  - 
    title: "ExportByteArray"
    link: "https://reference.wolfram.com/language/ref/ExportByteArray.en.md"
  - 
    title: "FunctionDeclaration"
    link: "https://reference.wolfram.com/language/ref/FunctionDeclaration.en.md"
  - 
    title: "CreateCompilerEnvironment"
    link: "https://reference.wolfram.com/language/ref/CreateCompilerEnvironment.en.md"
related_tutorials: 
  - 
    title: "Wolfram Compiler Manual"
    link: "https://reference.wolfram.com/language/CompilerManual/tutorial/Overview.en.md"
---
[EXPERIMENTAL]

# FunctionCompileExportByteArray

FunctionCompileExportByteArray[fspec] gives a byte array of binary LLVM code obtained by compiling the function specification fspec.

FunctionCompileExportByteArray[defs, fspec] uses the auxiliary definitions defs for compilation.

FunctionCompileExportByteArray[fspec, "format"] gives a byte array of binary code in the specified format.

## Details and Options

* Functions can be given as a ``Function`` pure function, a list of pure functions or an association of pure functions.

* Auxiliary definitions can be given with ``FunctionDeclaration`` or by giving a ``CompilerEnvironment`` option.

* Possible values for ``"format"`` include:

|              |                                          |
| ------------ | ---------------------------------------- |
| "LLVMBinary" | LLVM binary code                         |
| "Binary"     | machine code for a specific architecture |

* The following options can be given:

|                      |                 |                                               |
| -------------------- | --------------- | --------------------------------------------- |
| CompilerEnvironment  | Automatic       | an environment of definitions for compilation |
| CompilerOptions      | CompilerOptions | detailed options for the compilation pipeline |
| ProgressReporting    | Automatic       | how to report progress during the compilation |
| TargetSystem         | Automatic       | \$SystemID for the target architecture        |

* With the setting ``TargetSystem -> Automatic``, ``FunctionCompileExportByteArray`` will generate code for the machine architecture on which it is being run, including, for example, taking account of word length.

* In ``FunctionCompileExportByteArray[func, …]``, ``func`` can be a ``CompiledCodeFunction`` object.

---

## Examples (6)

### Basic Examples (3)

Generate a compiled version of a function and return the result as a byte array:

```wl
In[1]:= FunctionCompileExportByteArray[Function[Typed[arg, "MachineInteger"], arg + 1]]

Out[1]= ByteArray[CompressedData["«2235»"]]
```

---

Several functions can be compiled with ``FunctionCompileExportByteArray`` :

```wl
In[1]:= FunctionCompileExportByteArray[{Function[Typed[arg, "Integer64"], arg + 1], Function[Typed[arg, "Integer64"], arg - 1]}]

Out[1]= ByteArray[CompressedData["«3125»"]]
```

It can be useful to use an association to hold the functions:

```wl
In[2]:= FunctionCompileExportByteArray[<|"f1" -> Function[Typed[arg, "Integer64"], arg + 1], "f2" -> Function[Typed[arg, "Integer64"], arg - 1]|>]

Out[2]= ByteArray[CompressedData["«3089»"]]
```

---

Auxiliary definitions can be given with ``FunctionDeclaration`` :

```wl
In[1]:= FunctionCompileExportByteArray[FunctionDeclaration[AddTwo, Typed[{"Integer64"} -> "Integer64"]@Function[arg, 2 + arg]], Function[Typed[arg, "Integer64"], AddTwo[AddTwo[arg]]]]

Out[1]= ByteArray[CompressedData["«3187»"]]
```

### Options (3)

#### CompilerEnvironment (1)

Create a compiler environment and add a function definition:

```wl
In[1]:=
env = CreateCompilerEnvironment[];
CompilerEnvironmentAppendTo[env, {FunctionDeclaration[addTwo, Typed[{"Integer64"} -> "Integer64"]@Function[arg, 2arg]]}];
```

Use a compiler environment in a compilation:

```wl
In[2]:= FunctionCompileExportByteArray[ Function[{Typed[arg, "Integer64"]}, addTwo[arg]], CompilerEnvironment -> env]

Out[2]= ByteArray[CompressedData["«3023»"]]
```

#### ProgressReporting (1)

Progress during a compilation is reported:

```wl
In[1]:= FunctionCompileExportByteArray[Function[{Typed[s, "String"]}, ToCharacterCode[s]]]

In[2]:= [image]
```

This can be suppressed by setting the option ``ProgressReporting`` to ``False``.

The default value of ``ProgressReporting`` is ``Automatic``, which means that the global setting ``\$ProgressReporting`` is used. If this is set to ``False``, then no progress reporting takes place.

#### TargetSystem (1)

The default setting of ``Automatic`` generates code for the machine architecture on which it is being run:

```wl
In[1]:= FunctionCompileExportByteArray[Function[Typed[arg, "MachineInteger"], arg + 1]]

Out[1]= ByteArray[CompressedData["«2235»"]]
```

``TargetSystem`` can be set to the ``\$SystemID`` of the desired platform:

```wl
In[2]:= FunctionCompileExportByteArray[Function[Typed[arg, "MachineInteger"], arg + 1], TargetSystem -> "Linux-ARM"]

Out[2]= ByteArray[CompressedData["«2223»"]]
```

## See Also

* [`FunctionCompile`](https://reference.wolfram.com/language/ref/FunctionCompile.en.md)
* [`FunctionCompileExport`](https://reference.wolfram.com/language/ref/FunctionCompileExport.en.md)
* [`FunctionCompileExportString`](https://reference.wolfram.com/language/ref/FunctionCompileExportString.en.md)
* [`FunctionCompileExportLibrary`](https://reference.wolfram.com/language/ref/FunctionCompileExportLibrary.en.md)
* [`TargetSystem`](https://reference.wolfram.com/language/ref/TargetSystem.en.md)
* [`ExportByteArray`](https://reference.wolfram.com/language/ref/ExportByteArray.en.md)
* [`FunctionDeclaration`](https://reference.wolfram.com/language/ref/FunctionDeclaration.en.md)
* [`CreateCompilerEnvironment`](https://reference.wolfram.com/language/ref/CreateCompilerEnvironment.en.md)

## Tech Notes

* [Wolfram Compiler Manual](https://reference.wolfram.com/language/CompilerManual/tutorial/Overview.en.md)

## Related Guides

* [Code Compilation](https://reference.wolfram.com/language/guide/CodeCompilation.en.md)
* [C/C++ Language Interface](https://reference.wolfram.com/language/guide/CLanguageInterface.en.md)

## History

* [Introduced in 2019 (12.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn120.en.md) \| [Updated in 2021 (12.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn123.en.md)