Dynamically load Julia from Fortran.
This guide assumes that GFortran, Fortran Package Manager
and Git
are installed already.
wget https://julialang-s3.julialang.org/bin/linux/x64/1.6/julia-1.6.1-linux-x86_64.tar.gz
tar -xzf julia-1.6.1-linux-x86_64.tar.gz
export LD_LIBRARY_PATH=`pwd`/julia-1.6.1/lib
# ☝️ This one is important!
- Download and install https://julialang-s3.julialang.org/bin/winnt/x64/1.6/julia-1.6.1-win64.exe
- Add
C:\path\to\Julia-1.6.1\bin
to thePATH
environment variable, for example
set PATH=C:\Julia-1.6.1\bin;%PATH%
rem ☝️ This one is important!
- Not tested
(1) Create a new fpm project and cd into it
fpm new my-julia
cd my-julia
(2) Open file fpm.toml in your text editor and append this code:
[dependencies]
dynload-julia = { git = "https://github.com/brocolis/dynload-julia.git" }
(2.1) If your computer runs linux, add link = "dl"
to the [build]
section of fpm.toml
[build]
link = "dl"
(3) Open file app/main.f90 and replace everything with the following code:
program main
use julia, only: julia_init, julia_run, julia_destroy
use, intrinsic :: iso_c_binding, only: c_double
implicit none
real(kind=c_double), allocatable :: matf64(:,:)
call julia_init()
call julia_run("script.jl", matf64)
print *, 'Fortran: value computed by Julia:', matf64
call julia_destroy()
end program
(4) Create file script.jl in the project root directory
using LinearAlgebra
# Do stuff ...
return [1.1 2.2; 4.4 5.5]
(5) Build and run the project
fpm run