Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29313 Discussions

Weird problem, VC++ 2005 call different Fortran functions

wisperless
Beginner
907 Views

I have a main C++ function and I also added a Fortran as a static lib to this C++ project according to Steve's suggestion.

C++:


void A_FUN(int *A);

void B_FUN(int *B);

int main()

{

int a=1;

int b=1;

A_FUN(&a);

B_FUN(&b);

}

The two fortran functions, A_FUN ,is in a file called Fortran_File1.f90, and B_FUN, in a file called Fortran_File2.f90

Fortran_File1.f90 contains :

subroutine A_FUN(A)

end rubroutine

Fortran_File2.f90 contains

subroutine B_FUN(B)

end robroutine

If I comment out either A_FUN or B_FUN in C++ main funtion and compiled the solution, everything works fine. However, if I compile the solution with A_FUN and B_FUN. The compiler gave me thelink error
"error LINK 2001: unresolved external symbol "void _cdecl _B_FUN(int*)" ?(_B_FUN@@YAXPEAH0@Z).

Thank you in advance!

0 Kudos
1 Reply
TimP
Honored Contributor III
907 Views
What you show looks OK as C code. When you compile as C++ you need the extern "C" qualifiers to exclude the Fortran functions from name mangling.
0 Kudos
Reply