```rust
#![crate_type = "staticlib"]
-extern crate libc;
-
-use libc::c_char;
+use std::os::raw::c_char;
use std::ffi::CString;
#[no_mangle]
}
```
-Compile to object code with `rustc --emit=obj lib.rs`
+Compile to object code with `rustc --crate-type=staticlib lib.rs`
**test.c**
int main(void) {
char *str = hello();
-
printf("%s\n", str);
-
Rfree(str);
- return 0;
}
```
-Compile with `gcc lib.o test.c -o test`
+Compile with `gcc liblib.a test.c -o test -lpthread -ldl`
---
\f[C]
#![crate_type\ =\ "staticlib"]
-extern\ crate\ libc;
-
-use\ libc::c_char;
+use\ std::os::raw::c_char;
use\ std::ffi::CString;
#[no_mangle]
\f[]
.fi
.PP
-Compile to object code with \f[C]rustc\ \-\-emit=obj\ lib.rs\f[]
+Compile to object code with
+\f[C]rustc\ \-\-crate\-type=staticlib\ lib.rs\f[]
.PP
\f[B]test.c\f[]
.IP
int\ main(void)\ {
\ \ char\ *str\ =\ hello();
-
\ \ printf("%s\\n",\ str);
-
\ \ Rfree(str);
-\ \ return\ 0;
}
\f[]
.fi
.PP
-Compile with \f[C]gcc\ lib.o\ test.c\ \-o\ test\f[]
+Compile with
+\f[C]gcc\ liblib.a\ test.c\ \-o\ test\ \-lpthread\ \-ldl\f[]
.PP
* * * * *
.SS Wish list
@verbatim
#![crate_type = "staticlib"]
-extern crate libc;
-
-use libc::c_char;
+use std::os::raw::c_char;
use std::ffi::CString;
#[no_mangle]
}
@end verbatim
-Compile to object code with @code{rustc --emit=obj lib.rs}
+Compile to object code with @code{rustc --crate-type=staticlib lib.rs}
@strong{test.c}
int main(void) {
char *str = hello();
-
printf("%s\n", str);
-
Rfree(str);
- return 0;
}
@end verbatim
-Compile with @code{gcc lib.o test.c -o test}
+Compile with @code{gcc liblib.a test.c -o test -lpthread -ldl}
@iftex
@bigskip@hrule@bigskip