How to use juliac with imported packages?

I am trying to use juliac to turn some code into an executable. The following minimal example works:

module HelloWorld

Base.@ccallable function main()::Cint
    println(Core.stdout, "Hello, World!")
    return 0
end

end # End of module HelloWorld 
julia +nightly ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl --output-exe test_juliac --experimental --trim test_juliac.jl

But if test_juliac.jl uses any package, such as the following, I get “Package not found in current path”, even though I can then go into the REPL and use the package easily. Any ideas where this is happening and how to fix it?

module HelloWorld

using Plots

Base.@ccallable function main()::Cint
    println(Core.stdout, "Hello, World!")
    return 0
end

end # End of module HelloWorld 
1 Like

Try creating a Project.toml file including the packages you want to use, and then invoke juliac with julia +nightly --project ...

Here’s a slightly less minimal example

4 Likes

Thanks, indeed that seems to deal with the problem, but now I’m getting a segfault.

I’m also encountering other problems, I think related to certain packages. For instance, with Gtk4, I get:

ERROR: LoadError: could not load library ""
dlopen(.dylib, 0x0001): tried: '.dylib' (no such file)```

This functionality is not yet released, and there are likely many rough corners and issues left to iron out before it provides a smooth experience.

To get my demos to work, I had to remove some package dependencies to avoid loading them. I also inserted frequent debug printouts throughout the entire module and main function to pinpoint where segmentation faults appear. One of my demos also require patches not yet on Julia master, so once again, do not expect a smooth experience quite yet :slightly_smiling_face:

1 Like

Okay, thanks. I will mark your original comment as a solution since it does address the question about packages.