Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Calling Convetion Issue

einglez
Beginner
463 Views

I am working in MS Visual Studio 2005 in a mixed language project: Fortran and C++. Both languages are now working with C calling convention, but I need it to be stdcall. When I change the setting of my C++ project to _stdcall I got some linking errors like:

error LNK2019: unresolved external symbol _FUNCTION referenced in function _main

That function is called from the Fortran code (main).

I have a header file with a F77_FUNC() to deal with these function names calling convention thing, but I dont know how to change it to make it run in my project.

Maybe there is another form to make it run.

# define F77_FUNC(name,NAME) NAME
0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
463 Views

Consult the IVF documentation regarding mixed language function calls. This is a particularly confusing area of programming. Sometimes light can be shed on the subject by requesting the Assembler File to be produced. By examining that file you can see the actual names generated for the function calls as well as the calling convention (like who is responsible for cleaning the stack of arguments).

In a pinch, you can have Fortran call a shell C subroutine with one calling convention then call the C++ function using the other calling convention.

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
463 Views
My preferred way of dealing with this is to declare interface blocks for the C++ routines and add !DEC$ ATTRIBUTES STDCALL for the routines. You will probably also need attributes ALIAS and DECORATE, and perhaps REFERENCE. Simply changing the names is not sufficient - you must tell the compiler that the routines are STDCALL or else you'll corrupt the stack.

If you don't want to do this, you can change the default calling convention to "STDCALL, REFERENCE" (/iface:stdref from the command line) but you'll probably also have to use ALIAS and DECORATE unless the C++ routines are all lowercase.
0 Kudos
Reply