I have two projects: CPart
and FortranPart
in my solution. FortranPart
depends on CPart
and the later contains the main
function. Here is code of the main.c
#include <stdio.h>
extern int __stdcall FORTRAN_ADD(int *A, int *B);
int main()
{
int a = 3;
int b = 4;
int c = FORTRAN_ADD(&a, &b);
printf("%i\n", c);
return 0;
}
Here is code of my fortran module
module FORTRAN_UTILS
implicit none
contains
integer*4 function fortran_add(a, b) result(c)
implicit none
integer*4, intent(in) :: a, b
c = a + b
end function fortran_add
end module FORTRAN_UTILS
After the fortran is compiled I get the file FortranPart.lib
. In CPart
project dependencies I added it as external library. When I try to compile and run CPart
I get the following
Error LNK2019 unresolved external symbol _FORTRAN_ADD@8 referenced in function _main CPart c:\Users\sasha\documents\visual studio 2015\Projects\MSCourse\MSCourse\main.obj 1
P.S. I need the main program to be in C, not C++.
A little more research brought me this page https://software.intel.com/ru-ru/node/678422
I changed my code a little and now it's working.
and
main.c