In C++ functions with the same name but different content can be dropped in favor of only one of them.
So using the same name in different translation units is UB.
Has Rust the same behavior?
In my big project (worspace) I have two sqlite libraries compiled into Rust code,
they has different version plus patched and looks like cargo/rustc just silently drop one of implementation without any duplicate symbols errors.
I can reproduce it with
// foo/build.rs
fn main() {
cc::Build::new().file("foo.c").compile("foo");
}
// foo/foo.c
#include <stdint.h>
#include <stdio.h>
int32_t c_func(int32_t a, int32_t b)
{
printf("foo::c_func\n");
return a + b;
}
// foo/src/lib.rs
extern "C" {
pub fn c_func(a: i32, b: i32) -> i32;
}
// boo/build.rs
fn main() {
cc::Build::new().file("boo.c").compile("boo");
}
// boo/boo.c
#include <stdint.h>
#include <stdio.h>
int32_t c_func(int32_t a, int32_t b)
{
printf("boo::c_func\n");
return a + b;
}
// boo/src/lib.rs
extern "C" {
pub fn c_func(a: i32, b: i32) -> i32;
}
if compile these two crates into third one and call
#[no_mangle]
pub extern "C" fn my_f(a: i32, b: i32) -> i32 {
unsafe { foo::c_func(a, b) - boo::c_func(a, b) }
}
it prints
foo::c_func
foo::c_func
any way to get duplicate symbols error instead of such error prone silent?