JuliaC + HDF5

I was trying to compile an app using JuliaC and kept getting an error on the juliac step. I kept removing everything while keeping the error and until I was left with just one import. Here’s the MVE:

module Thing

import HDF5

function @main(args)
    println(Core.stdout, "hello")
    return 0
end

end

Here’s the error:

Precompiling packages finished.                   
  1 dependency successfully precompiled in 1 seconds. 60 already precompiled.
◒ Compiling...Error #1: unresolved call from statement !(
  isprecompiling()::Any                                                                                  
)::Any                         
                                                                                                         
Stacktrace:  
 [1] macro expansion     
   @ ~/.julia/packages/Requires/1eCOK/src/require.jl:97 [inlined]                                                                                                                                                  
 [2] __init__()
   @ HDF5 ~/.julia/packages/HDF5/Xsdf5/src/HDF5.jl:120
                                                    
Error #2: unresolved call from statement !(
  isprecompiling()::Any    
)::Any                    
                                                    
Stacktrace:               
 [1] macro expansion
   @ ~/.julia/packages/Requires/1eCOK/src/require.jl:97 [inlined]
 [2] __init__()
   @ HDF5 ~/.julia/packages/HDF5/Xsdf5/src/HDF5.jl:122

Error #3: unresolved call from statement (f::Any)()::Any

Stacktrace:
 [1] unknown scope
   @ ~/.julia/packages/Requires/1eCOK/src/require.jl:20
 [2] macro expansion
   @ ~/.julia/packages/Requires/1eCOK/src/require.jl:98 [inlined]
 [3] __init__()
   @ HDF5 ~/.julia/packages/HDF5/Xsdf5/src/HDF5.jl:120

Error #4: unresolved call from statement push!(
  callbacks(pkg::Base.PkgId)::Any,
  f::Any
)::Any

Stacktrace:
 [1] unknown scope
   @ ~/.julia/packages/Requires/1eCOK/src/require.jl:20
 [2] macro expansion
   @ ~/.julia/packages/Requires/1eCOK/src/require.jl:98 [inlined]
 [3] __init__()
   @ HDF5 ~/.julia/packages/HDF5/Xsdf5/src/HDF5.jl:120
Trim verify finished with 4 errors, 0 warnings.
✓ Compiling...
ERROR: Failed to compile Thing
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:44
 [2] compile_products(recipe::JuliaC.ImageRecipe)
   @ JuliaC ~/.julia/packages/JuliaC/CQ4OE/src/compiling.jl:267
 [3] _main_cli(args::Vector{String}; io::Base.TTY)
   @ JuliaC ~/.julia/packages/JuliaC/CQ4OE/src/JuliaC.jl:228
 [4] _main_cli(args::Vector{String})
   @ JuliaC ~/.julia/packages/JuliaC/CQ4OE/src/JuliaC.jl:219
 [5] main(ARGS::Vector{String})
   @ JuliaC ~/.julia/packages/JuliaC/CQ4OE/src/JuliaC.jl:234
 [6] _start()
   @ Base ./client.jl:583
ERROR: failed process: Process(`juliac Thing --output-exe Thing.exe --bundle build --trim`, ProcessExited(1)) [1]

Stacktrace:
 [1] pipeline_error
   @ ./process.jl:610 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base ./process.jl:525
 [3] run(::Cmd)
   @ Base ./process.jl:522
 [4] top-level scope
   @ REPL[2]:1

This is in the REPL, I’ve followed this example Self-contained juliac demonstration

Julia Version 1.13.2
Commit 45b6d15e34b (2026-10-14 20:33 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
  WORD_SIZE: 64
  LLVM: libLLVM-20.1.8 (ORCJIT, haswell)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 4 virtual cores)
Environment:
  JULIA_PKG_USE_CLI_GIT = true

The setup is correct; if I remove the import it works.

Sounds like you did with --trim, which requires any package you import to be --trim compatible. HDF5 isn’t, hence you get that error.

Works fine for me without passing --trim.

See GitHub - gbaraldi/StaticHDF5.jl: Read and write julia arrays to HDF5 · GitHub (no idea what the current status of that is though).

You were right. Compiling now.

HDF5.jl is not currently known to be compatible with --trim. I’m the maintainer. StaticHDF5.jl is the current solution.

That said it seems that you getting an error from Requires.jl which HDF5.jl has not used in some time. What version of HDF5.jl are using? What is the output of using Pkg; Pkg.status()?

I no longer have that env, I fixed as soon as someone mentioned --trim. Right now I’m on HDF5 0.17.4, but I can’t promise it’s the same that was in that previous env. But generally I try to use latest always.

Hey if I may ask a following up…
I’ve just successfully compiled something.

If used to run

julia -t 8 --project=. run.jl --arg1 lala

Now I’ve checked that

./mybin --arg1 lala

works, but how do I select the number of threads? Is that possible? Or does that get baked into the binary?

EDIT: sorted

JULIA_NUM_THREADS=8 ./mybin