Pregunta

I'm using Rust 0.11-pre to compile a simple staticlib

#![crate_type = "staticlib"]
#[no_mangle]
pub extern "C" fn foo() {  
}

And then I compile with

rustc foo.rs --crate-type="staticlib" -o foo.a

It's working fine, but I get the following warnings and I'm wondering how to resolve them

warning: unlinked native library: System
warning: unlinked native library: c
warning: unlinked native library: m
¿Fue útil?

Solución

I was working on something else, and happened to encounter this too: I know what's happening.

A Rust staticlib isn't linked against all its native dependencies. You need to link against those libraries when linking the staticlib into another program, e.g. on Linux, I had to compile gcc my_c_program.c -L . -lfoo -lc -lpthread -lm -ldl where foo.a was the Rust staticlib (in the current directory) and the last four args are the libraries that had a "unlinked native library" warning (strictly speaking the -lc is unnecessary, since the C compiler links against libc by default).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top