Rust + Intel Fortran LIB

Hello everybody

I just signed up for help. Really I can't.

I am on Windows 10, MSVC and Intel Fortran 9.0

My first idea was to test LAPACK (with crate LAPACK). No success. :frowning:

Now I am trying a very small problem. Still without success.

So I'm looking for a little example that really works.

For example with a Fortran LIB with code

opmath2.for

integer(c_int) function double_input (input) BIND (C)
     use iso_c_binding

     implicit none
     integer(c_int), VALUE :: input
     integer(c_int) double_input

     double_input = 2 * input

 end function

with main.rs

# [link (name = "opmath2")]
extern "C" {
    pub fn double_input (val: i32) -> i32;
}

fn main () {

    let v = 3;
    let _w = unsafe {double_input (v)};
    
}

Can someone give me a working example? Or a corresponding website.

Thanks

my LIB content

dumpbin /symbols /exports opmath2.lib
Microsoft (R) COFF/PE Dumper Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file opmath2.lib

File Type: LIBRARY

COFF SYMBOL TABLE
000 00000000 DEBUG  notype       Filename     | .file
    opmath2.f90
002 00000000 SECT1  notype       Static       | .drectve
    Section length   D3, #relocs    0, #linenums    0, checksum        0
004 00000000 SECT2  notype       Static       | .text
    Section length   10, #relocs    0, #linenums    0, checksum        0
006 00000000 SECT2  notype ()    External     | double_input
007 00000000 UNDEF  notype ()    External     | __ImageBase

run with cargo
cargo build

   Compiling mystatic v0.1.0 (C:\Users\Gilles\Documents\Projets\Rust\mystatic)
    Finished dev [unoptimized + debuginfo] target(s) in 2.67s

cargo run

    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `C:\Users\Gilles\Documents\Projets\Rust\mystatic\target\debug\mystatic.exe`
error: process didn't exit successfully: `C:\Users\Gilles\Documents\Projets\Rust\mystatic\target\debug\mystatic.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)


** AFTER ONE WEEK **

I ended up making myself a little C++ example called Fortran.

I had to do: (MSVC)
cl myCode.cpp myFortran.lib A.lib B.lib C.lib

where library A, B and C are Fortran lib.

If I look output of
cargo build I see
> .....
> ..... link.exe ... "/LIBPATH ....."/WHOLEARCHIVE:myFortran.lib"
> .....

How do I add A.lib B.lib and C.lib?

I have main.rs:


**main.rs**

> # [link (name = "myFortran")]
> extern "C" {
>     pub fn double_input (val: i32) -> i32;
> }
> 
> fn main () {
> 
>     let v = 3;
>     let _w = unsafe {double_input (v)};
>     
> }

Please follow our formatting guidelines:

You can edit your post to make the changes.

The #[link] directive is unfortunately mostly useless, because it will not know where to find the library you asked for.

You will need to write a build script that builds the fortran code and tells Cargo where it has been built.

1 Like

sorry

I created my LIB with Intel Fortran.

Then I put this LIB somewhere where Rust finds it.

I have the impression that it is when returning to Rust (Rust -> Fortran -> Rust) the problem

What error/symptoms are you seeing?

I think I've heard that fortran always takes all arguments by reference. Could that be it?

Also, the three backticks that end a code block must be on their own line. That's why your code is still formatted incorrectly.

Sorry for the format. I have to leave but I correct on the return.

Thank you

note: yes I saw for by reference and by value

look original post for error - thanks

Are you sure you're compiling everything for the same target (32 vs 64)? Looking online, it seems like sometimes people get these errors when using Fortran and they have not correctly chosen compilation targets. This seems like a low-level error (STATUS_ACCESS_VIOLATION).

If that does not work and your code is OK, then looking at the source code in blas-lapack may be helpful – but please note that the examples there aren't the same as what you're trying to do, write your own extern Fortran stuff.

I think I am in x64 everywhere. I will review. Thank you

for Blas-Lapack.
I will see if this could not inspire me. Thank you.