Are you an LLM? You can read better optimized documentation at /examples/embed/keil-mdk.md for this page in Markdown format
Related example project: Example
xmake will automatically detect the compiler installed by Keil/MDK, related issues #1753.
Compile with armcc
sh
$ xmake f -p cross -a cortex-m3 --toolchain=armcc -c
$ xmakeCompile with armclang
sh
$ xmake f -p cross -a cortex-m3 --toolchain=armclang -c
$ xmakeExecutable program
EXPLORER
src
main.c
xmake.lua
Lua xmake.lua
1234
target("hello")
add_rules("mdk.console")
add_files("src/*.c")
set_runtimes("microlib")
It should be noted that when some mdk programs all use the microlib library to run, it requires the compiler to add the __MICROLIB macro definition, and the linker to add various configurations such as --library_type=microlib.
We can set directly to the microlib runtime library through set_runtimes("microlib"), and all relevant options can be set automatically.
Static library program
EXPLORER
src
foo
foo.c
foo.h
main.c
xmake.lua
Lua xmake.lua
12345678910111213
add_rules("mode.debug", "mode.release")
target("foo")
add_rules("mdk.static")
add_files("src/foo/*.c")
set_runtimes("microlib")
target("hello")
add_rules("mdk.console")
add_deps("foo")
add_files("src/*.c")
add_includedirs("src/foo")
set_runtimes("microlib")