Skip to content

Create binary code file

zhaotianjing edited this page Feb 24, 2022 · 2 revisions

We will introduce how to make binary files. Below tutorial is based on the Julia package PackageCompiler.jl, please install it by

using Pkg
Pkg.add("PackageCompiler")

Method 1. Create sysimage file (.so)

The sysimage file is the compiled binary file. The package will be loaded automatically when we start julia with its sysimage file.

create sysimage file

julia> using PackageCompiler
julia> create_sysimage(["JWAS"]; sysimage_path="JWASsysimage.so")

The JWASsysimage.so file is about 200 Mb. It took a few minutes to create JWASsysimage.so file.

use sysimage file

julia is required

assume JWAS is not installed in your computer

> julia -J JWASsysimage.so 

You can see Base.loaded_modules that the complied JWAS has been loaded automatically.

Load the package by using .JWAS, instead of using JWAS, because the latter one requires UUID, while the computer does not install JWAS.

julia> using .JWAS

Method 2. Create executable file (aka. App)

"Use-cases for Julia-apps are for example when one wants to provide some kind of functionality where the fact that the code was written in Julia is just an implementation detail and where requiring the user to download and use Julia to run the code would be a distraction. There is also no need to provide the original Julia source code for apps since everything gets baked into the sysimage."

Assume JWAS is not installed in your julia. Firstly, download JWAS package from GitHub, then we will have a “JWAS.jl” folder.

> git clone https://github.com/reworkhow/JWAS.jl.git

Add a main function, see: https://discourse.julialang.org/t/how-to-use-the-app-generated-by-packagecompiler-jl/76994

create exe file

julia> using PackageCompiler
julia> create_app("JWAS.jl", "JWASCompiled")
julia> exit()

It took 10 minutes to create this app. Then we will see a folder named "JWASCompied". We can compress the folder by tar -zcvf JWASComplied.tar.gz JWASCompiled, the size of JWASComplied.tar.gz is 111 MB.

In the JWASCompied folder, there are three sub-folder named "lib", "bin", and "share". In "bin", there are two Unix Executable files: julia and JWAS.

use exe file

Julia is not required

see: https://discourse.julialang.org/t/how-to-use-the-app-generated-by-packagecompiler-jl/76994

Clone this wiki locally