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 C/C++ from Visual Fortran

Scott_Hill
Beginner
598 Views
I am trying to call some simple C programs from Visual Fortran and visa-vera. I used the Fortran-Calls-C example provided with the Visual Fortran Compiler, and it works fine as-is. However, if I change the name of the C routine or try calling an second C routine, I get a link error:
LNK2019: unresolved external symbol _routine_name referenced in function _MAIN__
I would appreciate any input or more robust examples.
Thank you.
Scott
0 Kudos
3 Replies
Steven_L_Intel1
Employee
598 Views
Please show us what you changed. Show the declaration of the routine in C and in Fortran. The examples are ok, but if you make changes without understanding the interactions that can cause trouble.
0 Kudos
TimP
Honored Contributor III
598 Views
The examples with USE ISO_C_BINDING might be considered "more robust" than the ones using legacy methods, and there you could use any examples from textbooks or on-line tutorials, as well as those in the ifort Windows docs.
0 Kudos
mecej4
Honored Contributor III
598 Views
In the Fortran-Calls-C case, there is a Fortran caller and a C callee, and there is a definite relation between the name of the C routine in the caller and the name of the same name in the callee. You cannot change the routine name in one place without breaking the program.

Even after you overcome the name matching problem, there will remain a bigger problem: matching routine arguments and their types, particularly if Fortran CHARACTER variables are used as arguments.

The documentation goes into all these issues and, if you are going to do mixed language programming, you have to read the relevant sections.
0 Kudos
Reply