---
title: "Using the Slice Compiler"
url: https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler
language: matlab
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Using the Slice Compiler

Programming language: MATLAB. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/js.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/php.md), [Python](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/swift.md).

## Common Options

Ice provides a Slice compiler for each language mapping. The compilers share a similar command-line syntax:

```shell
slice2<name> [options] file...
```

In MATLAB, you run the Slice-to-MATLAB compiler with the `slice2matlab` function of the Ice toolbox, as shown in [Running the Compiler](#running-the-compiler).

Regardless of which compiler you use, a number of command-line options are common to the compilers for any language mapping:

- `-h, --help` Displays a help message.
- `-v, --version` Displays the compiler version.
- `-DNAME` Defines the preprocessor symbol `NAME` with the value `1`.
- `-DNAME=DEF` Defines the preprocessor symbol `NAME` with the value `DEF`.
- `-UNAME` Undefines the preprocessor symbol `NAME`.
- `-IDIR` Add the directory `DIR` to the search path for `#include` directives.
- `--output-dir` `DIR` Place the generated files into directory `DIR`, which must already exist.
- `-d, --debug` Print debug information showing the operation of the Slice parser.

The following options print dependency information:

- `--depend-xml` Print dependency information in XML format to standard output by default, or to the file specified by the `--depend-file` option.
- `--depend-file FILE` Directs dependency information to the specified file.

With these options, the compiler prints the complete list of Slice files that the input Slice files depend on, through direct or indirect inclusion, and generates no code.

The Slice compilers permit you to compile more than a single source file, so you can compile several Slice definitions at once, for example:

```shell
slice2cpp -I. file1.ice file2.ice file3.ice
```

Each compiler predefines macros that identify the compiler and the Ice version; see [Conditional Compilation](https://docs.zeroc.com/ice/3.8/slice/slice-source-files.md#conditional-compilation).

## The Slice Compiler for MATLAB

The Slice-to-MATLAB compiler offers two additional options:

- `--all` Generate code for all Slice definitions, including those from included files.
- `--list-generated` Emit a list of generated files in XML format.

`slice2matlab` does **not** support the `--depend` flag, although it does still support `--depend-xml` and `--depend-file`.

### Running the Compiler

The Ice toolbox provides the Slice-to-MATLAB compiler and a `slice2matlab` function that runs it. You call this function from the MATLAB console or from a MATLAB script. It adds the directory of the Ice Slice files to the include search path, forwards its arguments to the compiler, and returns the compiler's exit status:

```matlab
slice2matlab Greeter.ice
status = slice2matlab('--output-dir', 'generated', 'Greeter.ice');
```

## See Also

- [Slice Compilation](https://docs.zeroc.com/ice/3.8/slice/slice-compilation.md)
