Re: How to link a Fortran static library to a C++ program?



Guch Wu wrote:
I build a Fortran static library whitch has a function using Intel
Visual Fortran 9.0. There is a function as follow:

subroutine sub(a)
implicit none
integer :: a
write(*,*) a
return
end subroutine

Now I link it to a C++ program in Visual C++ 2003:

#pragma comment( lib, "FLib.lib" )

#ifdef __cplusplus
extern "C"{
#endif

void _stdcall SUB(int *a);

#ifdef __cplusplus
}
#endif

int main(int argc, _TCHAR* argv[])
{
int a = 10;
SUB(&a);
return 0;
}

When building the C++ project, there is a problem:
error LNK2019: unresolved external symbol _SUB@4 referenced in function
_main

How can I fix the problem?

Read your compiler documentation as to mixed language linkage. Intel Fortran does not use STDCALL linkage in its default mode. Remove "_stdcall" from the C caller and things will work fine.

N. Shamsundar
University of Houston
.



Relevant Pages

  • Re: How to link a Fortran static library to a C++ program?
    ... subroutine sub ... unresolved external symbol _SUB@4 referenced in function ... Preferably, don't use stdcall. ...
    (comp.lang.fortran)
  • Re: A powerful tool for Visual Fortran - www.vftool.com
    ... I'd like to share one powerful tool for Visual Fortran with you. ... serves as a toolbar in Visual Fortran IDE, and it can do the following ... Go to the definition of a subroutine or function by name. ...
    (comp.lang.fortran)
  • A powerful tool for Visual Fortran - www.vftool.com
    ... I'd like to share one powerful tool for Visual Fortran with you. ... serves as a toolbar in Visual Fortran IDE, and it can do the following ... Go to the definition of a subroutine or function by name. ... Toggle view format of code between fixed and free format. ...
    (comp.lang.fortran)