---
title: "Using the Slice Compiler"
url: https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler
language: python
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: Python. 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), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/using-the-slice-compiler/php.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...
```

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` Print dependency information in Makefile format to standard output by default, or to the file specified by the `--depend-file` option.
- `--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. The output format depends on whether `--depend` or `--depend-xml` is specified.

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 Python

The Slice-to-Python compiler (`slice2py`) supports the following additional options:

- `--build=modules|index|all` Selects which Python files the compiler generates.
- `--list-generated=modules|index|all` Prints the paths of the Python files that the compiler would generate, relative to the output directory and one per line, without generating them.

The value selects the files:

| Value | Files |
| --- | --- |
| `modules` | The Python module files for the Slice definitions. |
| `index` | The Python package index files (`__init__.py`). |
| `all` | Both module and index files. What the compiler generates without `--build`. |

## See Also

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