# Calling fortran function

**URL:** https://discourse.julialang.org/t/calling-fortran-function/2288
**Category:** New to Julia
**Tags:** ccall, fortran
**Created:** [February 24, 2017, 9:59pm UTC](https://discourse.julialang.org/t/calling-fortran-function/2288 "2017-02-24T21:59:08Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)
#### Post date: [February 25, 2017, 2:14am UTC](https://discourse.julialang.org/t/calling-fortran-function/2288/9 "2017-02-25T02:14:18Z")

</div>

Also here is a simple example:

```fortran
subroutine foo1(n,x,y)
        integer*4, intent(in) :: n
        integer*4, intent(in), dimension(n) :: x
        integer*4, intent(out), dimension(n) :: y
        y = 2*x
end subroutine foo1

subroutine foo2(n,x,y)
        integer*8, intent(in) :: n
        integer*8, intent(in), dimension(n) :: x
        integer*8, intent(out), dimension(n) :: y
        y = 2*x
end subroutine foo2

```

Compile into a shared library, and then in Julia, e.g.:

```julia
ftest = Libdl.dlopen("ftest.dll")
t = ones(Int32,2)
ccall(Libdl.dlsym(ftest,:foo1_), Void, (Ref{Int32}, Ref{Int32}, Ptr{Int32}), Int32(2), Int32.([3, -1]), t)
println(t)
t = ones(Int64,2)
ccall(Libdl.dlsym(ftest,:foo2_), Void, (Ref{Int64}, Ref{Int64}, Ptr{Int64}), 2, [3, -1], t)
println(t)
Libdl.dlclose(ftest)

```

---

_[View the full topic](https://discourse.julialang.org/t/calling-fortran-function/2288)._
