-
Notifications
You must be signed in to change notification settings - Fork 5
Compiling with DUB and LDC
This page will show you how to compile LWDR with your project for an ARM Cortex-M microcontroller. The steps for other microcontrollers should be similar. This tutorial assumes you have some familiarity with DUB.
Before starting, here is some recommended reading:
Create a new dub project and add LWDR to it.
Add the following dflags
to your dub.json
or sdl
:
"dflags": [
"-mtriple=arm-none-eabi",
"-mcpu=cortex-m4",
"-g",
"-float-abi=hard",
"-O0",
"-fthread-model=local-exec"
],
For an STM32F407, which is a Cortex-M4, we must have the -mtriple=arm-none-eabi
to tell LDC that we are compiling for an ARM chip with no OS. -mcpu=cortex-m4
tells LDC which exact CPU we are using. -g
forces LDC to compile your project (and LWDR) with debug symbols. If your debugger does not support D, you may need to use -gc
instead, but the debugging capability will be less advanced. -float-abi=hard
notifies LDC that our CPU has hardware floating point support. -O0
tells LDC not to optimise our code (for debugging). If you are using TLS variables, you must include the -fthread-model=local-exec
flag so that LDC outputs TLS code that LWDR can work with.
Note: -g
full debugging capabilities are confirmed working on the GDB debugger.
Add the following dflags
to your dub.json
or sdl
:
"dflags": [
"-mtriple=arm-none-eabi",
"-mcpu=cortex-m4",
"-float-abi=hard",
"-O3",
"-fthread-model=local-exec"
],
For an STM32F407, which is a Cortex-M4, we must have the -mtriple=arm-none-eabi
to tell LDC that we are compiling for an ARM chip with no OS. -mcpu=cortex-m4
tells LDC which exact CPU we are using.-float-abi=hard
notifies LDC that our CPU has hardware floating point support. -O3
tells LDC to optimise your code and LWDR. If you are using TLS variables, you must include the -fthread-model=local-exec
flag so that LDC outputs TLS code that LWDR can work with.
Set your project as a static library. In your dub.json:
"targetType": "staticLibrary"
Compile with dub build --build=debug --compiler=ldc2
. This should generate a .a
or .lib
file which you can link against.
Compile with dub build --build=release --compiler=ldc2
. This should generate a .a
or .lib
file which you can link against.