google / cargo-raze

Generate Bazel BUILD from Cargo dependencies!
Apache License 2.0
478 stars 104 forks source link

ld linker error: duplicate symbols #529

Closed GOVYANSONG closed 1 year ago

GOVYANSONG commented 1 year ago

I have a binary project that depends on a lib project. they both expose a public function called mainshell(). the compilation worked fine but linking failed due to below error:

note: ld.lld: error: duplicate symbol: mainshell

defined at server_bin.c6e295fc-cgu.12 bazel-out/k8-fastbuild/bin/server_bin.server_bin.c6e295fc-cgu.12.rcgu.o:(mainshell) defined at uds_lib.b703c14a-cgu.4 uds_lib-1135776745.uds_lib.b703c14a-cgu.4.rcgu.o:(.text.mainshell+0x0) in archive /home/mk8s/.cache/bazel/_bazel_mk8s/9e3db3d0e00a003c34284dea09dfb92b/execroot/hot_restarter/bazel-out/k8-fastbuild/bin/external/raze__uds_pkg__0_1_0/libuds_lib-1135776745.rlib collect2: error: ld returned 1 exit status

the rustc should have disambiguate these two functions. maybe i am mssing a configuration somewhere. please assist.

GOVYANSONG commented 1 year ago

Just read about rustc disambuigation. apparently, the issue was caused by putting #[no_mangle] on both functions. after i removed this directive from one fn, the reported linker error disappeared.