I have 2 files:
func.rs
#[no_mangle]
pub extern fn double_input(input: i32) -> i32 { input * 2 }
main.c
#include <stdint.h>
#include <stdio.h>
extern int32_t double_input(int32_t input);
int main() {
int input = 4;
int output = double_input(input);
printf("%d * 2 = %d\n", input, output);
return 0;
}
I want to create a static lib in Rust and link the library to main.c. My active toolchain stable-i686-pc-windows-gnu
. I do this in cmd:
rustc --crate-type=staticlib func.rs
But the func.lib file is created , so I:
gcc -o myprog main.c func.lib -lgcc_eh -lshell32 -luserenv -lws2_32 -ladvapi32
But I get an error message:
undefined reference to __ms_vsnprintf'
If I do this:
rustc --crate-type=staticlib --target=i686-unknown-linux-gnu lib.rs
Then libfunc.a is created , but when I do this:
gcc -o myprog main.c libfunc.a
I get an error message:
main.c:(.text+0x1e): undefined reference to `double_input'
What am I doing wrong?
source
share