title: Calling C++ function from Fortran in Visual Studio 2010 with 2003 ISO C binding
body: <p>I have to call a C++ function from my fortran program. I am using Visual Studio 2010. I read the relevant chapter on 2003 ISO C binding in this book <a href="https://rads.stackoverflow.com/amzn/click/com/1848825420" rel="nofollow noreferrer" rel="nofollow noreferrer">http://www.amazon.com/Guide-Fortran-Programming-Walter-Brainerd/dp/1848825420</a> . I tried to compile and run the simple example at pag 219 (I copied it below) but it says "error LNK2019: unresolved external symbol _c referenced in function _MAIN__ ". These are the steps I have followed. </p>
  
  <p>1)I created a Fortran project with the Fortran main program and module and I set it as "startup project".</p>
  
  <p>2)I created a C++ project of type "static library". </p>
  
  <p>3)I added $(IFORT_COMPILERvv)\compiler\lib\ia32 as explained here <a href="http://software.intel.com/en-us/articles/configuring-visual-studio-for-mixed-language-applications" rel="nofollow noreferrer">http://software.intel.com/en-us/articles/configuring-visual-studio-for-mixed-language-applications</a></p>
  
  <p>When I compile I get that error. If I comment the Call C line it perfectly runs so it just cannot find the C function. Any suggestion? Thanks in advance. Here are the C and Fortran codes:</p>
  
  <pre><code>    module type_def
         use, intrinsic :: iso_c_binding
         implicit none
         private
  
         type, public, bind(c) :: t_type
            integer(kind=c_int) :: count
            real(kind=c_float) :: data
         end type t_type
      end module type_def
  
      program fortran_calls_c
         use type_def
         use, intrinsic :: iso_c_binding
         implicit none
  
         type(t_type) :: t
         real(kind=c_float) :: x, y
         integer(kind=c_int), dimension(0:1, 0:2) :: a
  
         interface
            subroutine c(tp, arr, a, b, m) bind(c)
               import :: c_float, c_int, c_char, t_type
               type(t_type) :: tp
               integer(kind=c_int), dimension(0:1, 0:2) :: arr
               real(kind=c_float) :: a, b
               character(kind=c_char), dimension(*) :: m
            end subroutine c
         end interface
  
         t = t_type(count=99, data=9.9)
         x = 1.1
         a = reshape([1, 2, 3, 4, 5, 6], shape(a))
         call c(t, a, x, y, "doubling x" // c_null_char)
         print *, x, y
         print *, t
         print *, a
  
      end program fortran_calls_c
  
      #include "stdafx.h"
      //#include &lt;iostream&gt;
      #include &lt;fstream&gt;
      typedef struct {int amount; float value;} newtype;
      void c(newtype *nt, int arr[3][2], float *a, float *b, char msg[])
      {
          printf (" %d %f\n", nt-&gt;amount, nt-&gt;value);
          printf (" %d %d %d\n", arr[0][1], arr[1][0], arr[1][1]);
          printf (" %s\n", msg);
          *b = 2*(*a);
      }
  </code></pre>