- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Topic Mix language- Calling Fortran subroutine from C++ code
C++ code
#include
extern "C"
{
void multi_(int *,int *,int * );
}
int main()
{
int x=2;
int y=3;
int xy;
multi_(&x,&y,&xy);
printf ("xy= %d",xy);
}
The following Fortran code was compiledand the created "static library *.lib" was copied to thefolderwhere above C++ code was compiled. The fortran static library *.lib was poited to in "additional Dependencies" in the linker configurationSUBROUTINE multi(x11,y11,xy11)
integer x11,y11,xy11
xy11=x11*Y11
return
end
However, I when compiling C++ code I get the following error
Error 1 error LNK2019: unresolved external symbol _multi_ referenced in function _main CProgAddApp.obj C-For-Interface
I really apprecite your help
shaw
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The name decoration depends on the compilers used and the target (32-bit or 64-bit) EXE type. For 32-bit Windows, the name in the C++ program (two places) should be MULTI.
When in doubt, use DUMPBIN to display the unsatisfied externals in the .OBJ file that the C++ compiler and Fortran compiler produce. You may also use compiler options to control the case of external names, (and, to some extent, the addition of leading and trailing underscores).
When in doubt, use DUMPBIN to display the unsatisfied externals in the .OBJ file that the C++ compiler and Fortran compiler produce. You may also use compiler options to control the case of external names, (and, to some extent, the addition of leading and trailing underscores).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
USE iso_c_binding
subroutine multi(x11,y11,z11) bind(c,name='multi_')
integer(C_INT) x11,y11,z11
....
Then you don't have to remember that Windows mangling is different from linux.
subroutine multi(x11,y11,z11) bind(c,name='multi_')
integer(C_INT) x11,y11,z11
....
Then you don't have to remember that Windows mangling is different from linux.

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