Hi! I created a Fortran code with 3 function. This is my Fortran code:
real function circle_area(radius)
!DEC$ ATTRIBUTES DLLEXPORT :: CIRCLE_AREA
!DEC$ ATTRIBUTES ALIAS : "Circle_Area" :: CIRCLE_AREA
implicit none
real radius
real, parameter :: PI = 3.14159
circle_area = radius*radius*PI
return
end function
integer function sum(a)
!DEC$ ATTRIBUTES DLLEXPORT :: SUM
implicit none
integer :: a(10)
integer i
sum=0
do i=1,10
sum=sum+a(i)
end do
return
end function
subroutine MakeLower(string)
!DEC$ ATTRIBUTES DLLEXPORT :: MAKELOWER
implicit none
character(len=*) :: string
integer :: len, i, code
len = len_trim(string)
do i=1,len
code = ichar(string(i:i))
if ( code >= ichar('a') .and. code <= ichar('z') ) then
string(i:i) = char(code-32)
end if
end do
return
end subroutine
I use this Fortran code to create dll (Dll1). Then I wrote a c program to call function circle_area() in Fortran code.
#include "stdafx.h"
#include "stdlib.h"
extern "C" {float circle_area(float *a); }
int _tmain(int argc, _TCHAR* argv[])
{
float b = 3.;
circle_area(&b);
system("pause");
return 0;
}
Before I ran my c code, I included my dll in Visual Studio 2013. First I added my Dll1.lib directory in VC++ directories-> Library Directories, in Linker -> General -> Additional Library Directories added Dll1.lib directory again, in Linker -> Input -> Additional Dependencies added Dll1.lib. Last, I put Dll1.dll in c project folder that it will create .exe together.
After running my c code, I got these messages :
error LNK2019: unresolved external symbol '_circle_area ' referenced in function '_wmain'
error LNK1120: 1 unresolved external symbol
It seems that I need something setup. Can someone help me?