I'm trying to link statically against library written in Rust:
#![crate_type = "staticlib"]
#[no_mangle]
pub extern "C" fn foo() {
println!("bork!");
}
Using following code in C:
void foo();
int main()
{
foo();
return 0;
}
Compile lib with rustc:
rustc foo.rs
Compile binary and link with library:
gcc -g bar.c libfoo.a -ldl -lpthread -lrt -lgcc_s -lpthread -lc -lm -o bar
Run inside debugger:
(gdb) run
Starting program: /home/kykc/rusttest/bar
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff72117df in __cxa_thread_atexit_impl (func=<optimized out>, obj=<optimized out>, dso_symbol=0x0) at cxa_thread_atexit_impl.c:67
67 cxa_thread_atexit_impl.c: No such file or directory.
gcc:
gcc-4.8.real (Ubuntu 4.8.2-19ubuntu1) 4.8.2
rustc:
rustc 1.0.0-beta (9854143cb 2015-04-02) (built 2015-04-02)
It works completely fine with dylib. What am I doing wrong?
rustc -g -C opt_level=0 foo.rsgcc -O0 -g bar.c libfoo.a -ldl -lpthread -lrt -lgcc_s -lpthread -lc -lm -o barproduces same result