Have simple mixed c++ main call to fortran subroutine working, but calling multiple subroutines from the same cmain.cpp is "different."

two separate function statements in c++ main to the fortran subroutines as
extern void _stdcall IADDTWO (long *i,long *j,long *k);
extern void _stdcall FSUB (double *c);
generate an
error LNK2001: unresolved external symbol "void __stdcall FSUB(double *)" (?FSUB@@YGXPAN@Z)

roughly the same thing occurs on reordering the statements:
error LNK2001: unresolved external symbol "void __stdcall IADDTWO(long *,long *,long *)" (?IADDTWO@@YGXPAJ00@Z)

running the cmain.cpp program with only a call to one or the other fortran routine works fine.

Alternatively, parsing the statement as
extern void _stdcall FSUB (double *c), IADDTWO (long *i,long *j,long *k);
alone has a successful link and "run." "run" is in quotes for the console application because the "illegal operation" message box activates. On closing the box, the program seems to terminate normally.

Guessing that directly aliasing the functions may work, but even if it does I'd like to understand what's going on with calls noted.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

C++ name mangling. Use:

extern "C" void ...

instead. This is discussed in the mixed-language programming chapter of the Programmer's Guide.


Retired 12/31/2016

Don't know much about mixed programming,
Don't know much about extern "C"

But it seemed to work from the call indicated in a recent string call discussion:
Reply From: Jugoslav Dujic
February 12,2002 6:15am

For the previous two _stdcall query, the following two statements work and the program terminates properly:

extern void _stdcall FSUB (double *c);
extern "C" void _stdcall IADDTWO (long *i,long *j,long *k);

Note that the standard

#ifdef __cplusplus
extern "C"

was invoked above the void function statement. The second forced reference worked and no aliasing was necessary in the fortran subroutine(s).

Thank you, Mr. Dujic et. al.

Leave a Comment

Please sign in to add a comment. Not a member? Join today