Hello,
I am trying to link a Cuda Fortran subroutine with an Intel Fortran program via a C interface. Here are my files:
!Main_file.f90
program test
use, intrinsic :: iso_c_binding
use :: sim_param
implicit none
interface
subroutine mmul_interface(a,b,c) bind(C)
use, intrinsic :: ISO_C_BINDING
integer, intent(in) :: a,b
integer, intent(out) :: c
end subroutine
end interface
write(,)'Input values ', val1, val2
call mmul_interface(val1,val2,sum)
write(,)'The sum is ', sum
end program test
!module.f90
module sim_param
implicit none
integer, parameter :: val1 = 143
integer, parameter :: val2 = -12
integer :: sum
contains
end module
!Library_interface.c
#include <stdio.h>
void cmod1_mmul(int* a, int* b, int* c);
void mmul_interface(int* a, int* b, int* c)
{
cmod1_mmul(a, b, c);
}
!engine.cuf
module cmod1
implicit none
contains
subroutine mmul(in1,in2,sum) bind(c)
use, intrinsic :: iso_c_binding
implicit none
integer, intent(in) :: in1, in2
integer, intent(out) :: sum
sum = in1 + in2
end subroutine mmul
end module cmod1
My solution in Visual studio is made by three projects: a console compiled using intel fortran (Main_file.f90, module.f90), a c static library (Library_interface.c) and a cuda fortran static library (engine.cuf). After linking the solutions together and comppiling I get the following errors:
Severity Code Description Project File Line Suppression State
Error error LNK2001: unresolved external symbol f90_compiled Interface_C.lib(engine.obj)
Error error LNK2001: unresolved external symbol ISO_C_BINDING Interface_C.lib(engine.obj)
Error error LNK2001: unresolved external symbol __pgdbg_stub Interface_C.lib(engine.obj)
Error fatal error LNK1120: 3 unresolved externals x64\Debug\Interface_reduced.exe
Then, I linked the cuda fortran static library with the library pgf90.lib. When I compile I get only one error:
Severity Code Description Project File Line Suppression State
Error fatal error LNK1120: 1 unresolved externals x64\Debug\Interface_reduced.exe
Error error LNK2001: unresolved external symbol __pgdbg_stub Interface_C.lib(engine.obj)
From I could understand the problem is related to loading the PGI libraries. Does anyone knows how to solve this problem?
Regards,
Riccardo