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

Calling a C function in Visual Studio from a Visual Fortran code

J_B_1
Beginner
618 Views

Hi,

I have a Visual Studio 2012 installed on Windows 8.1. Also, I installed Visual Fortran. I want to create a solution with two projects one in Fortran and one in C, then be able to call C function from Fortran code. Can anyone, please, show a simple step by step example on how to achieve this in VS? Thanks.

0 Kudos
2 Replies
Steven_L_Intel1
Employee
618 Views

There is a Fortran_Calls_C sample provided in Mixedlanguage.zip under Samples. But the general steps are:

  1. Create the executable project (Fortran in this case)
  2. Right click on the Solution under Solution Explorer and select Add... New Project...
  3. Select Visual C++ > Win32 > Win32 Project. Name the project whatever you want and also specify where it is to be placed.
  4. When the project wizard opens, click Next and then change Application Type to Static Library. Make any other changes you want here and click Finish.
  5. Right click on your Fortran project and select Project Dependencies, Under "Depends On" you will see your C++ project listed - check the box next to it, then click OK.

Now you have the projects set up properly. Make sure you are naming and calling the C++ routine properly. Using the Fortran standard features for C interoperability will be helpful. Note that if your source file is .cpp and not .c, you will need to add 'extern "C"' before any functions you want Fortran to call.

J_B_1
Beginner
618 Views

Thanks Steve.

 

0 Kudos
Reply