我有这个简单的Fortran 90程序:
subroutine apc_wrapper(i, j, k)
implicit none
integer*8, intent(in) :: i, j
integer*8, intent(out) :: k
double precision t
k = i + js
end subroutine
Run Code Online (Sandbox Code Playgroud)
编译为共享库
gfortran -O2 -shared -fPIC apc_wrapper.f90 -o apc_wrapper.so
Run Code Online (Sandbox Code Playgroud)
现在,我想从Julia调用这个子例程,带有所有整数参数,就像这样
i = 2
j = 3
k = 0
ccall( (:apc_wrapper_, "./apc_wrapper.so"), Void, (Ptr{Int64}, Ptr{Int64}, Ptr{Int64}), &i, &j, &k)
Run Code Online (Sandbox Code Playgroud)
但它不会起作用.k不会改变它的值并继续评估为0.
但是,如果我这样做
i = 2
j = 3
kk = [0]
ccall( (:apc_wrapper_, "./apc_wrapper.so"), Void, (Ptr{Int64}, Ptr{Int64}, Ptr{Int64}), &i, &j, kk)
Run Code Online (Sandbox Code Playgroud)
也就是说,使用数组存储输出,它的工作原理!调用子例程后,kk …