- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have battled the mixed language monster at the command line and have found victory. When I attempt the same battle in the Visual Studio IDE, I lose--badly.
I have two projects, one being Fortran and the other being a Win32 C++ project. I make a call from a C++ routine to a Fortran subroutine. When I go to build the solution, I get a link error for _for_open and _for_close.
Quoting from the Invetl Visual Fortran Compiler Documentation:
"If you are using Microsoft Visual C/C++ or Intel C/C++, the Microsoft integrated development environment can build mixed Fortran/C applications transparently, with no special directives or steps on your part."
I had to set the stdcall calling convention in order to get the naming convention to match. When I try to fix the _for_open and _for_close by adding LIBIFCORE.LIB to the mix, I can a great deal of link errors for some quickwin routines.
If I remove the stdcall calling convention and go with the defaults, I get the error that the called fortran subroutine cannot be found.
What non-special steps should I take to get this to work?
I have two projects, one being Fortran and the other being a Win32 C++ project. I make a call from a C++ routine to a Fortran subroutine. When I go to build the solution, I get a link error for _for_open and _for_close.
Quoting from the Invetl Visual Fortran Compiler Documentation:
"If you are using Microsoft Visual C/C++ or Intel C/C++, the Microsoft integrated development environment can build mixed Fortran/C applications transparently, with no special directives or steps on your part."
I had to set the stdcall calling convention in order to get the naming convention to match. When I try to fix the _for_open and _for_close by adding LIBIFCORE.LIB to the mix, I can a great deal of link errors for some quickwin routines.
If I remove the stdcall calling convention and go with the defaults, I get the error that the called fortran subroutine cannot be found.
What non-special steps should I take to get this to work?
Link Copied
16 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're going about it the wrong way.
If you are building a program with a C++ main and a Fortran library, do this:
1. In the Fortran project properties, set Libraries..Disable default library directives to No.
2. In Tools..Options..Projects..VC++ Directories, add the path to the Intel Fortran LIB folder to the list for Libraries.
If you are building a program with a C++ main and a Fortran library, do this:
1. In the Fortran project properties, set Libraries..Disable default library directives to No.
2. In Tools..Options..Projects..VC++ Directories, add the path to the Intel Fortran LIB folder to the list for Libraries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks--it worked perfectly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve, I am encountering a similar problem. The only difference is that in my case the main program is a fortran and the library iswritten in C++.The LINK error message is'error LNK 2019: unresolvedexternal symbol ....'. I did compiled/linked my programs using command-line (DOS in IA-32) and it worked. I am wondering is there any document which shows the 'correct' way (such as how to set project/source properties, where to put the path of a library, how to link a static library? etc) to build mixed language application in .NET IDE? Thanks in advance.
Tom Lin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
All that you should need is:
1. Make the C/C++ project a "dependent" of the Fortran project (right click on parent project, select Dependencies, check box for dependent project.)
2. Ensure that the library settings are compatible in both projects (multithread DLL, etc.)
1. Make the C/C++ project a "dependent" of the Fortran project (right click on parent project, select Dependencies, check box for dependent project.)
2. Ensure that the library settings are compatible in both projects (multithread DLL, etc.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve, It looks good. But thistime, the error message is
'error: problem during multi-file optimization compilation'
I have disabled all 'optimization' options (project or source). Do you know where is the error source? Thanks and have a great day.
Tom Lin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That message is a generic one from the pseudo-linker that the compiler invokes in case you used /Qipo. It is usually preceded by some other message - was it? What does the build log say? Usually xild (the tool complaining) says this if there is a missing or corrupted object or library.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve, Thanks for the response.
You are right. The followings were the messages shown after compilation:
error: problem during multi-file optimization compilation (code 1)
error: problem during multi-file optimization compilation (code 1).
fatal error cannot open "Csub.lib"
The second message is exactly the same as the first one. 'Csub.lib' is the C++ library which has all the C routines. This set of programs work fine using command-line. I guess I am not really familiar with the 'right' procedure to use .NET IDE to build an application. Thank you for your help. Have a great day.
Tom Lin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you solve the "cannot open Csub.lib" problem, the other two messages will go away.
If Csub is built as another project in the same solution, make that project a dependent of the Fortran project (right click on Fortran project, select Dependencies, and check the box for the Csub project.) Then rebuild. You can also add the .lib file as a "source file" to the Fortran project (not my first choice of solutions.)
If Csub is built as another project in the same solution, make that project a dependent of the Fortran project (right click on Fortran project, select Dependencies, and check the box for the Csub project.) Then rebuild. You can also add the .lib file as a "source file" to the Fortran project (not my first choice of solutions.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve, The same error messages appeared again.
What I did was (in the Fortran project dependences, I checked the box before Csub, i.e., the Fortran project depends on Csub) and (in the Fortran Build Order, Csub comes first and then the Fortran project). I did not change the Dependences of both Csub and the Solution which contains both projects. Both of them have shown in the projects is 'Csub' and the box before the Fortran project was NOT checked. Am I doing it right? Any other properties I need to change? Thanks for the help.
Tom Lin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That should do it. Hmm...
I suggest the fallback method of adding the .lib to the Fortran project.
I suggest the fallback method of adding the .lib to the Fortran project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have noticed on versions 9.0.024 and earlier that I had to put the path and library into the linker options in order to get the application to link even if the dependencies were marked. For example, I have the projects foo and bar in the solution and foo depends on bar. If I don't add the path to bar and add bar.lib into foo, things fail.
I have just installed 9.1, so I will see if this version has the same behavior. Steve, thanks for the great support you provide.
I have just installed 9.1, so I will see if this version has the same behavior. Steve, thanks for the great support you provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My problem is a little different. I want to make a dynamic link library that has both C++ and Fortran routines. The C++ code calls some of the fortran routines, fortran routines invoke C++ routines (callbacks), and both fortran and C++ routinesare exposed to the program that loads the .dll.
Can you point me to instructions for how to set up project(s) in Visual Studio 2003 .NET to make this work?
Thanks,
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve for your time and super support. This forum is extremely helpful to my current project. Steve, can you elaboratea little moreabout how toaddCsub library tomy current Fortran project. I am willing totry it to see how it works. Thanks again. Good day.
TomLin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Good Morning Steve,
A quick question. I noticed that in the configuration properties of my Fortran program. In Linker/Command Line, it reads
....... /SUBSYSTEM:CONSOLE Csub.lib
There is no directory before Csub.lib.Don't we need to tell the compiler where Csub.lib is?How do I add the directory to it? Thanks and have a great day.
Tom Lin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you're doing it this way, go to the Linker property page, Input, and add the full path under Additional Dependencies.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve. I did that and it work as expected.
Tom Lin

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