Julia package images provide object (native code) caches for Julia packages. They are similar to Julia'ssystem image and support many of the same features. In fact the underlying serialization format is the same, and the system image is the base image that the package images are build against.
Package images are shared libraries that contain both code and data. Like.ji
cache files, they are generated per package. The data section contains both global data (global variables in the package) as well as the necessary metadata about what methods and types are defined by the package. The code section contains native objects that cache the final output of Julia's LLVM-based compiler.
The command line option--pkgimages=no
can be used to turn off object caching for this session. Note that this means that cache files have to likely be regenerated. SeeJULIA_MAX_NUM_PRECOMPILE_FILES
for the upper limit of variants Julia caches per default.
While the package images present themselves as native shared libraries, they are only an approximation thereof. You will not be able to link against them from a native program and they must be loaded from Julia.
Since the package images contain native code, we must run a linker over them before we can use them. You can set the environment variableJULIA_VERBOSE_LINKING
totrue
to make the package image linking process verbose.
Furthermore, we cannot assume that the user has a working system linker installed. Therefore, Julia ships with LLD, the LLVM linker, to provide a working out of the box experience. Inbase/linking.jl
, we implement a limited interface to be able to link package images on all supported platforms.
Despite LLD being a multi-platform linker, it does not provide a consistent interface across platforms. Furthermore, it is meant to be used fromclang
or another compiler driver, we therefore reimplement some of the logic fromllvm-project/clang/lib/Driver/ToolChains
. Thankfully one can uselld -flavor
to set lld to the right platform
To avoid having to deal withlink.exe
we use-flavor gnu
, effectively turninglld
into a cross-linker from a mingw32 environment. Windows DLLs are required to contain a_DllMainCRTStartup
function and to minimize our dependence on mingw32 libraries, we inject a stub definition ourselves.
Dynamic libraries on macOS need to link against-lSystem
. On recent macOS versions,-lSystem
is only available for linking when Xcode is available. To that effect we link with-undefined dynamic_lookup
.
Similar tomulti-versioning for system images, package images support multi-versioning. If you are in a heterogeneous environment, with a unified cache, you can set the environment variableJULIA_CPU_TARGET=generic
to multi-version the object caches.
These are the Julia command line flags that impact cache selection. Package images that were created with different flags will be rejected.
-g
,--debug-info
: Exact match required since it changes code generation.--check-bounds
: Exact match required since it changes code generation.--inline
: Exact match required since it changes code generation.--pkgimages
: To allow running without object caching enabled.-O
,--optimize
: Reject package images generated for a lower optimization level, but allow for higher optimization levels to be loaded.Settings
This document was generated withDocumenter.jl version 1.8.0 onWednesday 9 July 2025. Using Julia version 1.11.6.