This commit is contained in:
Win 2024-06-03 16:35:44 +07:00
parent fc4b777577
commit d95ca2ad8d
6 changed files with 29 additions and 0 deletions

6
hello-rust/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "hello-rust"
version = "0.1.0"
edition = "2021"
[dependencies]

BIN
hello-rust/libmultiply.a Normal file

Binary file not shown.

BIN
hello-rust/main Executable file

Binary file not shown.

BIN
hello-rust/multiply.o Normal file

Binary file not shown.

12
hello-rust/src/main.rs Normal file
View File

@ -0,0 +1,12 @@
extern crate core;
use core::ffi::c_int;
extern "C" {
fn multiply(a: c_int, b: c_int) -> c_int;
}
fn main() {
unsafe {
println!("Result: {}", multiply(100, 5));
}
}

11
hello-rust/src/multiply.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
#include <stdint.h>
int32_t multiply(int32_t a, int32_t b) {
printf("[C] Hello from C!\n");
printf("[C] Input a is: %i \n", a);
printf("[C] Input b is: %i \n", b);
printf("[C] Multiplying and returning result to Rust..\n");
return a * b;
}