- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.

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