Closed mssun closed 3 days ago
It looks like compiler-builtins isn't being linked in for dylibs. I don't know if that is expected behavior, but you can try to work around this by adding a dependency to compiler-builtins.
If you're trying to make a dynamic library for use with things other than Rust, the cdylib
crate type is probably what you're looking for.
@sfackler, thanks for the suggestion.
Actually, I'm doing some simple experiments and found that my code could be compiled on the x86_64-unknown-linux-gnu target but failed on the x86_64-apple-darwin target.
I don't know if that is expected behavior or a bug in rustc.
I'm hitting this same error with a cdylib when compiling in debug mode - is that intended ?
Undefined symbols for architecture x86_64:
"_memcpy", referenced from:
If I compile with --release
, the error disappears.
Triage: i do not have access to a macos machine. Are folks still seeing this?
@steveklabnik Same error for rustc 1.46.0-nightly (346aec9b0 2020-07-11)
.
$ cat lib.rs
#![feature(lang_items)]
#![no_std]
use core::panic::PanicInfo;
#[lang = "eh_personality"] extern fn eh_personality() {}
#[panic_handler] fn panic_fmt(_info: &PanicInfo) -> ! { loop {} }
pub fn foo() { }
$ rustc lib.rs --crate-type dylib
Undefined symbols for architecture x86_64:
"_memcmp", referenced from:
...
I'm using macOS 10.15.5.
I will argue that this is the "expected" behaviour, and that this issue should be closed:
You are asking rustc
to build without a standard library, and as such it makes perfect sense that it also isn't linking standard system libraries (passes -nodefaultlibs
to Clang). Never mind that that will basically never work for dynamic libraries on macOS/Darwin, as those are required by dyld
to link to libSystem.dylib
.
If you add either the following, or use -Clink-arg=-lSystem
, the error disappears.
#[link(name = "System", kind = "dylib")]
extern "C" {}
I briefly considered if rustc
could try to detect these cases, but I don't think that's really feasible, since there are many libraries that will result in linking libSystem.dylib
implicitly, for example libc.dylib
.
There is even a test for this here.
@rustbot label A-linkage
Closing as this is as intentional.
There is an error in link time when compiling a dynamic library which is
no_std
in macOS.Here is the
lib.rs
:Compile it:
Some version info:
I read some code of
linker.rs
, but still did not find the reason. If someone can point out the main reason, I am glad to help.