- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am a trying to call C++ function (named: evapdh) in a DLL (edmlib.dll) from a compaq visual fortran 6.6 (CVF) program that I have written. The edmlib.dll file was created by a colleague of mine. In my fortran code I have called evapdh in
the following manner: call evapdh(ev,dh)
Where ev and dh are arrays of type real*4 of length 8 & 5 respectively
Upon building my program I get the following linker error:
Compiling Fortran...
C:MARIMari3.f
Linking...
Mari3.obj : error LNK2001: unresolved external symbol _EVAPDH@8
Debug/Mari.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Mari.exe - 2 error(s), 0 warning(s)
I read about the LNK2001 error and I think I need to account for the "_" and "@8"
which has been added to the function name. Am I correct in this assumption?
I've read about "ATTRIBUTES Properties and Calling Conventions" in the CVF online help and included the following code in my fortran program to account for the function name mangling:
INTERFACE
SUBROUTINE evapdh (ev,dh)
cDEC$ ATTRIBUTES C, ALIAS:'_evapdh@8' :: evapdh ! ia32 systems
REAL*4 ev(8), dh(5)
END SUBROUTINE evapdh
END INTERFACE
However, Including this above code caused compilation errors:
Compiling Fortran...
C:MARIMari3.f
C:MARIMari3.f(1615) : Error: Syntax error, found ',' when expecting one of: ( : % . = =>
cDEC$ ATTRIBUTES C, ALIAS:'_evapdh@8'::evapdh ! ia32 systems
----------------------------^
C:MARIMari3.f(1615) : Error: Syntax error, found '::' when expecting one of: , : ) ] /)
cDEC$ ATTRIBUTES C, ALIAS:'_evapdh@8'::evapdh ! ia32 systems
-----------------------------------------------^
C:MARIMari3.f(1619) : Error: Syntax error, found END-OF-FILE when expecting one of:
the following manner: call evapdh(ev,dh)
Where ev and dh are arrays of type real*4 of length 8 & 5 respectively
Upon building my program I get the following linker error:
Compiling Fortran...
C:MARIMari3.f
Linking...
Mari3.obj : error LNK2001: unresolved external symbol _EVAPDH@8
Debug/Mari.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Mari.exe - 2 error(s), 0 warning(s)
I read about the LNK2001 error and I think I need to account for the "_" and "@8"
which has been added to the function name. Am I correct in this assumption?
I've read about "ATTRIBUTES Properties and Calling Conventions" in the CVF online help and included the following code in my fortran program to account for the function name mangling:
INTERFACE
SUBROUTINE evapdh (ev,dh)
cDEC$ ATTRIBUTES C, ALIAS:'_evapdh@8' :: evapdh ! ia32 systems
REAL*4 ev(8), dh(5)
END SUBROUTINE evapdh
END INTERFACE
However, Including this above code caused compilation errors:
Compiling Fortran...
C:MARIMari3.f
C:MARIMari3.f(1615) : Error: Syntax error, found ',' when expecting one of: ( : % . = =>
cDEC$ ATTRIBUTES C, ALIAS:'_evapdh@8'::evapdh ! ia32 systems
----------------------------^
C:MARIMari3.f(1615) : Error: Syntax error, found '::' when expecting one of: , : ) ] /)
cDEC$ ATTRIBUTES C, ALIAS:'_evapdh@8'::evapdh ! ia32 systems
-----------------------------------------------^
C:MARIMari3.f(1619) : Error: Syntax error, found END-OF-FILE when expecting one of:
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The general format for compiler directives is (from the manual)
but it goes on to say that C (or c) is only allowed in fixed-format files.
Use !DEC$ instead, which is valid in all formats. HTH
cDEC$ ATTRIBUTES att [, att] ... :: object [, object] ... c s one of the following: C (or c), !, or *. See Syntax Rules for General Directives.)
but it goes on to say that C (or c) is only allowed in fixed-format files.
Use !DEC$ instead, which is valid in all formats. HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Name mangling with C calling convention is different than in STDCALL:
- In C, it'll be "_myCfunc" (or "myCfunc_" on some compilers)
- In STDALL, it'll be "_myCfunc@4".
However, VC++ (and other compilers, each in their own way) will apply by default "C++ name mangling", to enable overloading, kinda "?_myCfunc@YAXXUZ". (Use dumpbin /exports somecppdll.dll to see what I mean) That decoration contains full info about argument and return types, but it's undesired in mixed-language. You have to use extern "C" statement for "exported" C++ routines to prevent that from happening.
Jugoslav
- In C, it'll be "_myCfunc" (or "myCfunc_" on some compilers)
- In STDALL, it'll be "_myCfunc@4".
However, VC++ (and other compilers, each in their own way) will apply by default "C++ name mangling", to enable overloading, kinda "?_myCfunc@YAXXUZ". (Use dumpbin /exports somecppdll.dll to see what I mean) That decoration contains full info about argument and return types, but it's undesired in mixed-language. You have to use extern "C" statement for "exported" C++ routines to prevent that from happening.
Jugoslav

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page