“multiple definition of `memcmp” error when linking Rust staticlib with embedded C program

这一生的挚爱 提交于 2019-12-02 05:53:06
attdona

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);
  ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!