---
source_path: "api/compile-macros.md"
canonical_url: "https://doc.sensory.com/tnl/7.8/api/compile-macros/"
---

# Compile-time macros

These optional preprocessor macros apply to the native [C][] API only. They are
not used by the [Java][], [Python][], or Android Java/Kotlin bindings.

Define library macros before `#include <snsr.h>`, or pass them as compiler
flags (for example `-DSNSR_USE_SUBSET`). Define generated-model macros before
compiling [snsr-edit](https://doc.sensory.com/tnl/7.8/tools/snsr-edit.md#snsr-edit) output (files such as
_spot-voicegenie-enUS-6.5.1-m.c_
or _snsr-custom-init.c_).

For SDK-provided read-only values such as [VERSION](https://doc.sensory.com/tnl/7.8/api/constants.md#version), see [Constants](https://doc.sensory.com/tnl/7.8/api/constants.md#constants).

## Library initialization

By default, [new](https://doc.sensory.com/tnl/7.8/api/inference.md#new) maps to `snsrNewIncludeOSS()`, which initializes the full
library including Open Source components (STT support). You can select a
smaller variant instead.

| Macro | `snsrNew()` expands to | When to use |
|-------|------------------------|-------------|
| *(none)* | `snsrNewIncludeOSS()` | Default. Full library with OSS/STT. |
| [`SNSR_OMIT_OSS_COMPONENTS`](https://doc.sensory.com/tnl/7.8/api/compile-macros.md#snsr-omit-oss-components) | `snsrNewOmitOSS()` | Omit OSS/STT modules. See also [SnsrLibraryOmitOSS](https://doc.sensory.com/tnl/7.8/api/build-system.md#build-cmake). |
| [`SNSR_USE_SUBSET`](https://doc.sensory.com/tnl/7.8/api/compile-macros.md#snsr-use-subset) | `snsrNewSubset()` | Custom init code for a fixed model set. Mutually exclusive with `SNSR_OMIT_OSS_COMPONENTS`. |

### Details: `snsrNew()` selection (C)

```c
#ifndef SNSR_USE_SUBSET
#  ifdef SNSR_OMIT_OSS_COMPONENTS
#    define snsrNew(s) snsrNewOmitOSS((s), SNSR_VERSION)
#  else
#    define snsrNew(s) snsrNewIncludeOSS((s), SNSR_VERSION)
#  endif
#else
#  define snsrNew(s) snsrNewSubset((s), SNSR_VERSION)
#endif
```

### SNSR_USE_SUBSET

Limits the linked library to modules required by models you include in the
build. Requires custom initialization code that implements `snsrNewSubset()`.

Generate the init file with [snsr-edit](https://doc.sensory.com/tnl/7.8/tools/snsr-edit.md#snsr-edit) `-i`, or at runtime with [save](https://doc.sensory.com/tnl/7.8/api/inference.md#save)
and [SUBSET_INIT](https://doc.sensory.com/tnl/7.8/api/inference.md#fm_subset_init) after setting [model:ids](https://doc.sensory.com/tnl/7.8/api/setting-keys/runtime.md#modelids).
Add the generated _snsr-custom-init.c_ to your project and compile with
`-DSNSR_USE_SUBSET`.

**Also see these related items:** [reduce code size](https://doc.sensory.com/tnl/7.8/faq.md#reduce-code-size), [model:ids](https://doc.sensory.com/tnl/7.8/api/setting-keys/runtime.md#modelids), [snsr-eval.c](https://doc.sensory.com/tnl/7.8/api/sample/c/snsr-eval.md#snsr-evalc)

### SNSR_OMIT_OSS_COMPONENTS

Selects `snsrNewOmitOSS()`, which initializes the library without the Open
Source Software components (and therefore without STT). Those modules are then
unreferenced, so the linker can drop them and reduce executable size.

With [CMake](https://doc.sensory.com/tnl/7.8/api/build-system.md#build-cmake), the separate `SnsrLibraryOmitOSS` target adds this
define for you. With [Make](https://doc.sensory.com/tnl/7.8/api/build-system.md#build-make), add `-DSNSR_OMIT_OSS_COMPONENTS` to
`CFLAGS`.

**Also see these related items:** [Open Source licenses](https://doc.sensory.com/tnl/7.8/licenses/oss.md#open-source-licenses), [oss-components](https://doc.sensory.com/tnl/7.8/api/setting-keys/library-information.md#oss-components)

## Linkage

These macros control how public API symbols are declared in `<snsr.h>`. Most
applications leave them at their defaults.

### SNSR_API

Prefixes each public function declaration in `<snsr.h>`. Empty by default.
Override when you need custom export or visibility attributes (for example
when building a shared library wrapper).

Emscripten builds set `SNSR_API` to `__attribute__((used))` automatically.

### SNSR_DLL

When defined before `#include <snsr.h>` on Windows, sets `SNSR_API` to
`__declspec(dllimport)` for applications that link against a DLL build of
the SDK. The standard distribution ships static libraries only; Windows DLLs
are provided through custom SDK ports.

## Generated model code

[snsr-edit](https://doc.sensory.com/tnl/7.8/tools/snsr-edit.md#snsr-edit) emits C source with `-c` (run from ROM/code space) or `-C`
(load into RAM). [save](https://doc.sensory.com/tnl/7.8/api/inference.md#save) with [SOURCE](https://doc.sensory.com/tnl/7.8/api/inference.md#fm_source), [SOURCE_RAM](https://doc.sensory.com/tnl/7.8/api/inference.md#fm_source_ram),
or [SOURCE_PRUNED](https://doc.sensory.com/tnl/7.8/api/inference.md#dataformat) produces the same pattern. Each generated file
defines default values for the macros below unless you define them first.

Define overrides on the compiler command line, in a wrapper header included
before the generated file, or in your build system before the translation unit
is compiled.

### SNSR_MODEL_ATTR

Applied to every static model object in generated code (weights, strings,
tables, and the exported [fromCode](https://doc.sensory.com/tnl/7.8/api/io.md#fromcode) model symbol). Defaults to empty.

Override to control linker placement — for example, force model data into a
specific flash section on embedded targets:

```c
#define SNSR_MODEL_ATTR __attribute__((section(".model_flash")))
#include "spot-voicegenie-enUS-6.5.1-m.c"
```

`.model_flash` above is an example; use the section name your own linker script
defines. On toolchains without GCC-style attributes, define `SNSR_MODEL_ATTR`
to the macro or pragma your linker expects.

### SNSR_ALIGNED

Used as `SNSR_ALIGNED(n)` on selected model blobs in generated code. On GCC
and Clang the default expands to `__attribute__((aligned(n)))`; on other
compilers it defaults to empty.

Override when your toolchain needs a different alignment syntax.

<!-- Reference definitions from includes/links.md -->
[C]: https://en.wikipedia.org/wiki/C_(programming_language) "C programming language"
[Java]: https://en.wikipedia.org/wiki/Java_(programming_language) "Java programming language"
[Python]: https://en.wikipedia.org/wiki/Python_(programming_language) "Python programming language"

<!-- Abbreviation definitions from includes/abbreviations.md -->
*[API]: Application Programming Interface
*[OSS]: Open-source software
*[RAM]: Random Access Memory
*[ROM]: Read-Only Memory, typically nonvolatile flash memory
*[SDK]: Software Development Kit
*[STT]: Speech To Text: transformers with language model and CTC decoding
*[TNL]: TrulyNatural, Sensory's large-vocabulary speech recognition technology
