Merge pull request #35 from tungli/master

fortran example
This commit is contained in:
Alex Crichton
2020-03-02 13:41:06 -06:00
committed by GitHub
4 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
[package]
name = "rust-to-fortran"
version = "0.1.0"
build = "build.rs"
[dependencies]
libc = "0.2"
[build-dependencies]
cc = "1.0"

7
rust-to-fortran/build.rs Normal file
View File

@@ -0,0 +1,7 @@
extern crate cc;
fn main() {
cc::Build::new()
.file("src/double.f90")
.compile("libdouble.a");
}

View File

@@ -0,0 +1,16 @@
module wrapper
implicit none
private
public double_input
contains
function double_input(input)
implicit none
integer :: input, double_input
double_input = 2*input
end function
end module wrapper

View File

@@ -0,0 +1,13 @@
extern crate libc;
// Consider using the `nm` utility on compiled Fortran files to get the function names
extern {
fn __wrapper_MOD_double_input(input: &libc::c_int) -> libc::c_int;
}
fn main() {
let input = 4;
let output = unsafe { __wrapper_MOD_double_input(&input) };
println!("{} * 2 = {}", input, output);
}