- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using MS VS 6.0 for a c++ application which need to call a dll built with IVF (Version 9.0.2945.2003). The code which I have in C++ and Fortran is given below.
C++:
#include "stdafx.h"
#include
extern "C"
{
void __cdecl TestCode();
}
int main(int argc, char* argv[])
{
TestCode();
return 0;
}
FORTRAN:
subroutine TestCode
!DEC$ ATTRIBUTES DLLEXPORT::TestCode
!DEC$ ATTRIBUTES C, ALIAS: 'TestCode':: TestCode
call MainExp()
end subroutine TestCode
The TestCode.dll and .lib are in path of the C++ exe. Building the project gives following error.
Test.obj : error LNK2001: unresolved external symbol _TestCode
Debug/Test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Do I need to change something in vc++ project settings to get it right. Please help.
Regards,
Pradeep
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve
I have made the changes as follows:
subroutine
TestCode !DEC$ ATTRIBUTES DLLEXPORT:: TestCode !DEC$ ATTRIBUTES C, DECORATE, ALIAS: '_TestCode':: TestCode !call MainExp() print*, "Say Hello from Fortran"end subroutine
TestCodeStill the linker gives error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Be sure that you do not do BOTH of the things I mentioned. Use DECORATE and have the ALIAS omit the underscore.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
IusedDECORATE and ALIAS without the leading underscore. The only thing I forgot to do was to include the .lib in c++ project. Now I have added .lib to roject and kept .lib and .dll in path of c++ exe. It works fine now. Thanks for your help. Final code is as below:
---------------------Fortran Code--------------------
subroutine
TestCode !DEC$ ATTRIBUTES DLLEXPORT:: TestCode !DEC$ ATTRIBUTES C, DECORATE, ALIAS:'TestCode':: TestCode print*, "Say Hello from Fortran"end subroutine
TestCode#include
"stdafx.h"------------------C++ code -------------------
extern
"C"{
void __cdecl TestCode();}
int
main(int argc, char* argv[]){
TestCode();
return 0;}
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page