---
title: Build Integration
description: Wire the installed C SDK into a downstream project with the
  CLI-installed toolchain and makefiles.
source_url:
  html: https://thru.org/docs/sdks/c-reference/build-integration/
  md: https://thru.org/docs/sdks/c-reference/build-integration.md
---

# Build Integration

Use this page when you need to compile a C program against the installed SDK instead of just reading header-level reference docs.

## Prerequisites

Start with [Set Up Thru DevKit](https://thru.org/docs/program-development/setting-up-thru-devkit.md), then install the C SDK surfaces with:

```bash
thru dev toolchain install
thru dev sdk install c
```

The CLI installs the C SDK under `~/.thru/sdk/c` and the toolchain under `~/.thru/sdk/toolchain`.

## Verify the installed layout

```bash
test -d ~/.thru/sdk/c
test -f ~/.thru/sdk/c/thru-sdk/thru_c_program.mk
test -d ~/.thru/sdk/toolchain/bin
test -x ~/.thru/sdk/toolchain/bin/riscv64-unknown-elf-gcc || test -x ~/.thru/sdk/toolchain/bin/riscv64-none-elf-gcc
```

The downstream makefiles auto-detect either `riscv64-unknown-elf-` or `riscv64-none-elf-`, so either compiler prefix is valid.

## Main build entrypoint

The installed downstream build hook is `thru_c_program.mk`.

Its job is to:

- require `THRU_C_SDK_DIR`
- add SDK include paths through `CPPFLAGS`
- add SDK library paths through `LDFLAGS`
- include machine and config files for the Thru VM toolchain

## Minimal `GNUmakefile`

```makefile
THRU_C_SDK_DIR := $(HOME)/.thru/sdk/c/thru-sdk
include $(THRU_C_SDK_DIR)/thru_c_program.mk
```

## Minimal `Local.mk`

```makefile
$(call make-bin,my_program_c,my_program,,-ltn_sdk)
```

## What `THRU_C_SDK_DIR` should point to

Point it at the installed SDK root that contains:

- `thru_c_program.mk`
- `include/`
- `lib/`
- `config/`

For the default CLI install, that means:

```makefile
THRU_C_SDK_DIR := $(HOME)/.thru/sdk/c/thru-sdk
```

## Project layout that works well

```text
my-program/
├── GNUmakefile
└── examples/
    ├── Local.mk
    ├── my_program.c
    └── my_program.h
```

## Build-system guidance

| Need | Recommendation |
| - | - |
| One or two small programs | Keep a single `GNUmakefile` plus per-directory `Local.mk` files. |
| Multiple example binaries | Add more `make-bin` calls in `Local.mk`. |
| SDK extras | Use `SDK_EXTRAS` when you intentionally want extra configuration layers. |

## Expected build output

For the standard downstream project layout used in the C guide, the built binary lands under:

```text
build/thruvm/bin/
```

That is the path shape the rest of the docs currently assume for deployment examples.

## Notes

- The docs page is the right place to learn the installed entrypoint. The repo-local `sdks/c/setup.sh` is not the end-user install path you should default to.
- If a task is “build a downstream program,” start with `thru_c_program.mk`, not the SDK’s internal `GNUmakefile`.
