Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29271 Discussions

Multi-Lanuage Project (Visual Studio 2008) with C++ and FORTRAN

proud2bhaole
Beginner
544 Views
Hi,

I have a project that contains both .f90, .f (FORTRAN) and C++ files. The C++ code calls functions in the fortran files.

I have installed the Intel Visual Fortran software.

What steps do i need to do in order to get the C++ and Fortran files to both be compiled when I choose 'build'? Do i need to specify a custom build rule for the FORTRAN files?

Is there a way to compile all the fortran code as a library then point to it in the project thru the linker? I tried making a dll using the Fortran code but received an error when I tried to compile the entire project (C++ plus Fortran DLL file). I also tried creating a .lib file using a Fortran project. This didn't work either.

I have pointed to the directory that the .lib and .dll file is in and am still getting the errors below.

Currently the project type is Visual C++. Is there another project type that supports multilanguage?

Any help is appreciated.

currently these are the errors I'm receiving. All functions are Fortran Functions

------ Build started: Project: adsa1, Configuration: Debug Win32 ------
Linking...
ADSAP.obj : error LNK2019: unresolved external symbol _LMDER1@48 referenced in function _AdsaLM
ELLIP.obj : error LNK2001: unresolved external symbol _LMDER1@48
ADSAP.obj : error LNK2019: unresolved external symbol _DPOSVM@28 referenced in function _AdsaNT
ADSAP.obj : error LNK2019: unresolved external symbol _ENORM@8 referenced in function _AdsaNT
PROFILE.obj : error LNK2019: unresolved external symbol _DVERK@40 referenced in function _DropProfileData
PROFILE.obj : error LNK2019: unresolved external symbol _INTRP@36 referenced in function _DropProfileIntrp
.\Debug/adsa1.exe : fatal error LNK1120: 5 unresolved externals
Build log was saved at "file://c:\Student\Kevin\AdsaInterf 3.0 source\Debug\BuildLog.htm"
adsa1 - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
0 Kudos
1 Reply
Steven_L_Intel1
Employee
544 Views
You can't mix Fortran and C++ code in a single project. To build a mixed-language application, you need a solution with two projects, one for each language. One of these will usually be an executable (or DLL) project and the other a static library.

Let's say that the main program is in C++ and the routines are in Fortran. Create your C++ project first in a new solution. Add the C++ files to it. Then add a new project of type Fortran > Static Library to the solution. Add the Fortran files to it. Now do the following:

- Right click on the C++ project and select Dependencies. Check the box for the Fortran project to make it a dependent of the C++ project.
- Right click on the Fortran project and select Properties > Fortran > Libraries. Set the property "Disable default library search rules to "No".
- Make sure that the run-time library types match between the C++ and Fortran projects (for example, if C++ is using Multithreaded DLL, Fortran must be too

There is a one-time configuration of C++ you need to make to link in Fortran code - see the instructions at Configuring Visual Studio for Mixed-Language Applications

Now you can build the Solution and it should build and link properly.

I notice you have STDCALL routines being called. I assume those are the Fortran routines. If you're coming from Compaq Visual Fortran, you'll probably want to set the Calling Convention: CVF option in the Fortran project.

By the way, if you did have a CVF project with mixed sources, you can convert it to the split project solution automatically. See Migrating from Compaq* Visual Fortran
0 Kudos
Reply