Therefore, in Intel Fortran, we no longer require the __stdcall put ahead of the fortran functions in the C code. Instead, __stdcall should be replaced by __cdecl or simply be removed. The original codes in the website become
(1) The C++ file:
// This illustrates how a Fortran routine and function may be
// called from a main program in C++
#include
extern "C"
{
void FR1(int*,int *);
int FF1(int *);
}
int main()
{
int n=10,nSq,nCube;
FR1(&n,&nSq);
cout << "The square is:" << ncube="FF1(&n);" style="font-weight: bold;"> (2) The Fortran File:
SUBROUTINE FR1(N,M)
C COMPUTES THE SQUARE OF N, RETURNS IN M
M=N*N
RETURN
END
C
INTEGER FUNCTION FF1(N)
C COMPUTES THE CUBE OF N
FF1=N*N*N
RETURN
END
To build mixed-language the VS2005 project, it is not similar to what we did in VS6.0 where we put both C++ files and fortran files in the same project and then compile them together as a whole. In VS2005, we should separate them into two projects, one for C++ and one form Fortran.
Create a static library package for Fortran files by File > New> Intel Fortran > Library > Static Library when creating the package. - Create a Win32 console application package for C++ files by File > New> Visual C++ > Win32 console application
- Create a VS2005 solution by going to File > New > Other Studio solutions > VS solution and add both created packages in.
- Add the Fortran and C++ into their packages respectively.
- Right-click both packages to confirm their runtime libraries are consistent. For C++, it is at Property > C/C++ > Code Generation > runtime library. For Fortran, it is at Property > Fortran > Libraries and also make sure that "Disable OBJCOMMENT ....." is set to be NO
- Add the new created lib file (from the Fortran package) into the solution by add the Fortran package name (FortranName.lib) at Property > Linker > Input > Additional dependence by right-click the C++ package
- Add the additional library path for C++ package by going to Tools > Options > Projects and Solutions > Library files and click the white boards to add Intel Fortran library at \IntelFortranRoot\Compiler\Fortran\versioncode\IA32\Lib and the location where the new lib file is generated.
- After all these settings, I successfully my first package built under VS2005.