Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28517 Discussions

Call in C++ a subroutine from fortran lib

Tangy62
Beginner
483 Views

We have problems calling a subroutine from a static Fortran library in C++ (Visual Studio 2019 and Intel Fortran Compiler 2023)

The Fortran code:

subroutine TestFunc() bind(C, NAME="TestFunc")
INTEGER a, b,r
a = 5
b = 3
r = a + b

end subroutine

 

The C++ code:

extern "C" {void TestFunc();}

int main()

{
TestFunc();

return 0;
}

 

I get always the error message "unresolved external symbol "_TestFunc" in function "_main")

I have tried out a lot of different extern "C" definitions und different project settings, such as path settings to the Fortran library. I also manually copied the Fortran lib file into different directories.

Where is my mistake?

I had also tried it with a dynamic Fortran library (with !DEC$ ATTRIBUTES DLLEXPORT::TestDllFortran). I get the same error message.

I read many similar issues in different forums. But nothing help.

 

 

 

0 Kudos
2 Replies
Arjen_Markus
Honored Contributor I
454 Views

One trivial reason why this does not work is that the link step does not include the library. Can you check the dependencies to make sure that it is part of the link step? I know it is trivial, but at the moment it is the only reason I can think of.

0 Kudos
Tangy62
Beginner
440 Views

I have create a new project-solution and project and now it works. I suspect that due to the many attempts I made, another setting was no longer correct.

0 Kudos
Reply