Skip to content

Mixing C and Assembly source code

Felipe Torrezan edited this page Jan 28, 2024 · 5 revisions

Introduction

This interactive example describes the configuration details for when, in a CMake project, a target is comprised of C sources (*.c) and Assembly sources (*.s).

Tutorial

A CMake project example is provided at:

Project files
CMakeLists.txt
fun.h
fun.s
main.c

The public function fun() in fun.s returns 42 and is consumed by the application's main() function.

Tasks

Perform the following tasks on CMakeLists.txt (click to show/hide answers):

TODO 1: Enable Assembly for the project
project(Mix LANGUAGES C ASM)
TODO 2: Add `fun.s` source to the `mix` target in the `CMakeLists.txt`
target_sources(mix PRIVATE 
                   main.c
                   fun.s)

Finally build and test the project. Refer to the tutorial for more information.

Clone this wiki locally