문제

System: Windows-7-64-bit/Visual-Studio-2010/Intel-Visual-Fortran-11.

I am creating 32-bit executables.

Fortran routine declaration

SUBROUTINE LA01BD(N,M,L,A,B,C,X,F,IA,IPRINT,IND,WK,IER)
  !DEC$ ATTRIBUTES DLLEXPORT::LA01BD
  !DEC$ ATTRIBUTES STDCALL,REFERENCE,ALIAS:"LA01BD"::LA01BD
  use, intrinsic :: ISO_C_BINDING

C++ function signature declaration

extern "C" {void __stdcall LA01BD(int *N, int *M, int *L, double *A, double *B, double *C, double *X, double *F, int *IA, int *IPRINT, int *IND, double *WK, int *IER); }

I created the dll from fortran code using Visual Studio 2010 and Intel Visual Fortran compiler 11. I checked the exported symobol in dependency walker and the Function is "LA01BD".

When using the same dll (the .lib file during linking) in my C++ project, I get the following linker error.

lpwrap.obj : error LNK2001: unresolved external symbol _LA01BD@52

I am unable to resolve this issue. What does suffix "@52" does? How to fix the linking issue?

Thanks.

도움이 되었습니까?

해결책

The C++ compiler applies name decoration to the identifier. The __stdcall decoration is a leading _underscore and a trailing @n where n is the size of the activation frame.

The ALIAS directive in your Fortran code caused this problem, you forced it to be exported as "LA01BD" instead of "_LA01BD@52". You should first try to remove it so the normal name decoration is applied. If that's not an option then you'll need to either create an import library with lib.exe /def from a properly crafted .def file or fallback to late binding with GetProcAddress().

다른 팁

If you must use the STDCALL calling convention, then add the DECORATE attribute to the Fortran side to instruct the compiler to decorate the specified alias.

SUBROUTINE LA01BD(N,M,L,A,B,C,X,F,IA,IPRINT,IND,WK,IER)
!DEC$ ATTRIBUTES DLLEXPORT::LA01BD
!DEC$ ATTRIBUTES STDCALL,REFERENCE,ALIAS:"LA01BD"::LA01BD
!DEC$ ATTRIBUTES DECORATE :: LA01BD

it is caused by name mangling, please ref this for details. I guess you missed the extern "c" in your C++ project.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top