- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to write a basic program in C++ that calls a routine and a function from Fortran. I found this example on the web ( http://www.neurophys.wisc.edu/comp/docs/notes/not017.html) and have been trying to duplicate it. I'm getting three errors when I try to build:
error: LNK2019: unresolved external symbol _Main__ referenced in function_main (coming from Fortran project)
error: LNK2019: unresolved external symbol _FF1@4 reference in function_main (coming from C++ project)
error: LNK2019: unresolved external symbol _FR1@8 reference in function_main (coming from C++ project)
My directives look like this for my subroutine:
!DEC$ ATTRIBUTES DLLEXPORT ::FR1
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_FR1@8' :: FR1
And this for my function(which is in the subroutine)
!DEC$ ATTRIBUTES DLLEXPORT :: FF1
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_FF1@4' :: FF1
C++ section looks like this:
extern "C" void _stdcall FR1(int*,int *); extern "C" int _stdcall FF1(int *); void main(){
int n=10,nSq,nCube;FR1(&n,&nSq);
nCube=FF1(&n);
}
Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is at least one problem you have in that the Fortran project is looking for a main program. This means that either you created the Fortran project as an executable application (Console, etc.) rather than static library, or you have run into a bug in older versions of Intel Visual Fortran where every source got linked. Most likely the former.
You want to create a static library project for the Fortran code and make it a "dependent" of the C++ project. (If you have VS2005, make sure it also has SP1 applied.) In the Fortran project, set the property Libraries > Disable default library search rules to "No". Under Tools > Options > Projects > VC++ Directories, add the path to the Fortran installation LIB folder to "Library Files".
If in fact you have done all of these but still get the Fortran code linked, in the Fortran project go to the Fortran > Command Line property page and add /c to the Additional Options text.
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
There is at least one problem you have in that the Fortran project is looking for a main program. This means that either you created the Fortran project as an executable application (Console, etc.) rather than static library, or you have run into a bug in older versions of Intel Visual Fortran where every source got linked. Most likely the former.
You want to create a static library project for the Fortran code and make it a "dependent" of the C++ project. (If you have VS2005, make sure it also has SP1 applied.) In the Fortran project, set the property Libraries > Disable default library search rules to "No". Under Tools > Options > Projects > VC++ Directories, add the path to the Fortran installation LIB folder to "Library Files".
If in fact you have done all of these but still get the Fortran code linked, in the Fortran project go to the Fortran > Command Line property page and add /c to the Additional Options text.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks.
I was initializing everything as console applications. Working fine now.

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