Based on the tutorial of PackageCompiler.jl, I am using the following to create a sysimage: julia --project=. _create_sysimage.jl. That file contains:
_create_sysimage.jl:
import Pkg
Pkg.add("PackageCompiler")
Pkg.add("Example")
import PackageCompiler
PackageCompiler.create_sysimage(
["Example"];
sysimage_path="ExampleSysimagePrecompile.so",
precompile_execution_file="_precompile_execution.jl"
)
and
_precompile_execution.jl:
import Example
Example.hello("somestring")
If I now try to use that sysimage, by calling
julia -JExampleSysimagePrecompile.so -e 'import Example; Example.hello("friend")'
it does not find Example:
ERROR: ArgumentError: Package Example not found in current path, maybe you meant `import/using .Example`.
Now I thought the sysimage to be a way to “package” the current state of my Julia session - which would include the package Example, that I am also explicitly passing to the packages argument of create_sysimage(...) - which apparently is not the case.
Running
julia --project=. -JExampleSysimagePrecompile.so -e 'import Example; Example.hello("friend")'
instead (which loads the temporary project, that Pkg.add(...) installed Example into), works. But why doesn’t the first one work too?