Here is how it works for me:
Fortran interface
module julia_interface
use ISO_C_BINDING
implicit none
public :: print_name
private
CONTAINS
subroutine print_name(name, length)
character(kind=C_CHAR, len=length), intent(in) :: name
integer, intent(in) :: length
print *, name
end subroutine print_name
end module julia_interface
Julia ccall
str = "foo"
ccall(
(:julia_interface_mp_print_name_, "./julia_interface.so"),
Cvoid,
(Cstring, Ref{Int32}),
str, length(str)
)
Honestly, I still don’t understand exactly what is happening under the hook. I learned a bit about Fortran during the past two days, with the sole purpose of wrapping a subroutine in Julia. I assume Julia will automatically add a \0 to foo so the actual length is 4, which is not needed on the Fortran side?