- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I built a fortran DLL library, and I want to call the subroutines from C++, but I get the following error.
MessengerServer.obj : error LNK2001: unresolved external symbol __imp__ENGAGEABILITY_INIT@0
Debug/MessengerServer.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
I declared the dll subroutines as follows:
extern "C" __declspec(dllimport) void _stdcall ENGAGEABILITY_INIT();
this is in C++ file.
I also export the subroutine from the fortran side.
subroutine Engageability_Init()
!DEC$ ATTRIBUTES DLLEXPORT :: ENGAGEABILITY_INIT
What am I doing wrong?
Thanks
I built a fortran DLL library, and I want to call the subroutines from C++, but I get the following error.
MessengerServer.obj : error LNK2001: unresolved external symbol __imp__ENGAGEABILITY_INIT@0
Debug/MessengerServer.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
I declared the dll subroutines as follows:
extern "C" __declspec(dllimport) void _stdcall ENGAGEABILITY_INIT();
this is in C++ file.
I also export the subroutine from the fortran side.
subroutine Engageability_Init()
!DEC$ ATTRIBUTES DLLEXPORT :: ENGAGEABILITY_INIT
What am I doing wrong?
Thanks
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It sounds as if you did not insert yourdll.lib (from YourDllDir/Debug) into VC++ project.
Jugoslav
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do have the dll.lib included in the project setting under link tab. But, I still get the unresolved external symbol error.
I do have the access to the fortran source code, is it easier to bypass using dll and include the Fortran source directly in the C++ project and use it? How would I do this?
I do have the access to the fortran source code, is it easier to bypass using dll and include the Fortran source directly in the C++ project and use it? How would I do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I prefer to have it directly inserted into project (as any other source file). If you list it in Project/Settings/Link, you have to specify full path there (or add the path in Tools/Options/Directories/Library files).
It is possible to mix F90 and C++ files directly in one project -- just insert them together (and remove dllexport/dllimport directives).
It is possible to mix F90 and C++ files directly in one project -- just insert them together (and remove dllexport/dllimport directives).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Still having no luck with the unresolved external symbol error. I tried including the source directly in the project and removed the dll directives, and I still get the same error message.
Any possible leads?
Any possible leads?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sigh... I've got no more clues. Attached is a sample mixed-language workspace so I can only suggest you perform some comparisons.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran function that I'm trying to call from C++ is a member of Fortran module, could this be the problem?
In Fortran, I type "use [moduleName]", do I need to do a similar thing in C++?
In Fortran, I type "use [moduleName]", do I need to do a similar thing in C++?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that's it! CVF mangles module procedure names as _MODULENAME_mp_ROUTINENAME@n (case matters). You can either refer to it in C under that name, or use ALIAS directive in Fortran to rename it to something nicer:
Jugoslav
MODULE Something ... SUBROUTINE ENVIRONMENT_INIT() !DEC$ATTRIBUTES ALIAS: "_EnvironmentInit@0":: ENVIRONMENT_INIT ... extern "C" void __stdcall EnvironmentInit(void);
Jugoslav
![](/skins/images/D2683F18326913BBA0436CB7114DD569/responsive_peak/images/icon_anonymous_message.png)
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