I have a Rust function I would like to call from a C project that runs on an STM32F412 MCU, but I am getting a series of \"multiple definition of\" linker errors.
He
You have a bunch of duplicated symbols coming from your customized "standard library" liba
and from generated builtin symbols inserted into librust.a
:
memset, memcpy, memmove, ecc, ecc
Your problem arises because the order of object files matters when linking.
If you put librust.a
too early in the ordered sequence of files to link, then files before librust.a
will resolve symbols from librust.a
and files coming after librust.a
will resolve the same symbols from liba
and this generates duplicate symbol errors.
To avoid this problem, put the Rust library at the end of object files to link.
In epsilon Makefile change the link commands as:
RUST_LIB_DIR = <path_to_librust.a>
.SECONDARY: $(objs)
%.$(EXE):
@echo "LD $@"
$(Q) $(LD) $^ $(LDFLAGS) -L$(RUST_LIB_DIR) -l:librust.a -o $@
This recipe links successfully on my side.
My basic epsilon/apps/main.cpp
instrumentation:
#include "global_preferences.h"
#include "apps_container_storage.h"
extern "C" int hello_world(int a, int b);
void ion_main(int argc, char * argv[]) {
hello_world(1,2);
...