• ...
  • SDK
  • Yocto
  • ...
  • ...
  • your first application
  • tools
  • ...

Getting started with C/C++#

If you want to create a SimpleSwitch™ application using C/C++, please follow this guide to get you easily started.

Example Project#

Here is a very small C project, with a single C source file, test.c:

// SPDX-FileCopyrightText: (C) 2025 Tria Techonologies GmbH
// SPDX-License-Identifier: LicenseRef-Avnet-OSS-1.0
#include <stdio.h>
#include <unistd.h>

int main()
{
	while(1) {
		fprintf(stderr, "Test C SDK\n");
		sleep(5);
	}

	return 0;
}

And a Makefile:

# SPDX-FileCopyrightText: (C) 2022 Avnet Embedded GmbH
# SPDX-License-Identifier: LicenseRef-Avnet-OSS-1.0
BIN = c_test_prog
OBJS = test.o
PREFIX ?= ""

all: $(BIN)

$(BIN): $(OBJS)
	$(CC) -o $@ $<

clean:
	rm -f $(BIN) $(OBJS)

install: $(BIN)
	install -m 0755 -d "$(PREFIX)/opt/$(BIN)"
	install -m 0755 $(BIN) "$(PREFIX)/opt/$(BIN)"

.PHONY: clean install

One can build this project for the host system by putting both file in the same directory and running make

make
./c_test_prog
Test C SDK

Build the project using a Makefile#

With a makefile aware of cross-compilation, building the binary is as simple as sourcing the SDK (see Source the SDK) and running make, e.g.

make

If the makefile has an install target using the PREFIX variable as installation path, it can be used directly with the --makefile-dir option of the Generate a SimpleSwitch™ package script

  simpleswitch-generate-package --name simpleswitch-example --makefile-dir . \
  --template C --startup-command /opt/c_test_prog/c_test_prog

Or if you want to be able to debug your application:

simpleswitch-generate-package --name simpleswitch-example --makefile-dir . \
  --template C --startup-command "while true; do gdbserver :2159 /opt/c_test_prog/c_test_prog ; done"

If your makefile lack of a compatible install target, see below.

Deploy to the target#

Now it is time to deploy the generated SimpleSwitch™ container to the device. For this please see Deploy a SimpleSwitch™ package

Remote debugging a C/C++ application#

To remote debugging a C or a C++ application, you can see Remote debug a SimpleSwitch™ package

Further reading#