Gtk.jl + PackageCompiler.jl

Hallo @sdanisch.

I am new to Julia (and programming) and am playing around with a few packages to gain experience. I want to make a GUI in Gtk.jl and then make it and executable file with PackageCompiler.jl to share with non-programmers.

Lets use a dummy program:

using Gtk

win = GtkWindow("My First Gtk.jl Program", 400, 200)

b = GtkButton("Click Me")
push!(win,b)

showall(win)

How do I build an executable? I have tried this:

julia> using PackageCompiler

julia> build_executable("Test.jl", "Test")
Julia program file:
  "C:\Users\posthumusjj\Desktop\Test\Test.jl"
C program file:
  "C:\Users\posthumusjj\.juliapro\packages\PackageCompiler\BBtC7\examples\program.c"
Build directory:
  "C:\Users\posthumusjj\Desktop\Test\builddir"
ERROR: LoadError: ArgumentError: Package Gtk not found in current path:
- Run `import Pkg; Pkg.add("Gtk")` to install the Gtk package.

Stacktrace:
 [1] require(::Module, ::Symbol) at .\loading.jl:823
 [2] include at .\boot.jl:317 [inlined]
 [3] include_relative(::Module, ::String) at .\loading.jl:1044
 [4] include(::Module, ::String) at .\sysimg.jl:29
 [5] include(::String) at .\client.jl:392
 [6] top-level scope at none:0
in expression starting at C:\Users\posthumusjj\Desktop\Test\Test.jl:1
ERROR: failed process: Process(`'C:\JuliaPro-1.0.2.1\Julia-1.0.2\bin\julia.exe' -Cnative '-JC:\Julia
Pro-1.0.2.1\Julia-1.0.2\lib\julia\sys.dll' --compile=yes --depwarn=yes --startup-file=no --compiled-
modules=no --output-o Test.a -e 'Base.__init__(); Sys.__init__() # initialize \`Base\` and \`Sys\` m
odules
pushfirst!(Base.DEPOT_PATH, "cache_ji_v1.0.2") # save precompiled modules locally
include("C:\\\\Users\\\\posthumusjj\\\\Desktop\\\\Test\\\\Test.jl") # include Julia program file
'`, ProcessExited(1)) [1]
Stacktrace:
 [1] pipeline_error at .\process.jl:705 [inlined]
 [2] #run#504(::Bool, ::Function, ::Cmd) at .\process.jl:663
 [3] run(::Cmd) at .\process.jl:661
 [4] (::getfield(PackageCompiler, Symbol("##4#5")))() at C:\Users\posthumusjj\.juliapro\packages\Pac
kageCompiler\BBtC7\src\static_julia.jl:261
 [5] cd(::getfield(PackageCompiler, Symbol("##4#5")), ::String) at .\file.jl:85
 [6] build_object(::String, ::String, ::String, ::Bool, ::Nothing, ::Nothing, ::Nothing, ::Nothing,
::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, :
:Nothing, ::Nothing) at C:\Users\posthumusjj\.juliapro\packages\PackageCompiler\BBtC7\src\static_jul
ia.jl:260
 [7] #static_julia#1(::Nothing, ::Bool, ::Bool, ::Nothing, ::String, ::Nothing, ::Bool, ::Bool, ::Bo
ol, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Nothing, ::Bool, ::Bool, ::Nothing, ::Nothing, ::Nothi
ng, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothin
g, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::typeof(static_julia), ::String) at C:\Us
ers\posthumusjj\.juliapro\packages\PackageCompiler\BBtC7\src\static_julia.jl:172
 [8] #static_julia at .\none:0 [inlined]
 [9] #build_executable#22 at C:\Users\posthumusjj\.juliapro\packages\PackageCompiler\BBtC7\src\api.j
l:104 [inlined]
 [10] build_executable at C:\Users\posthumusjj\.juliapro\packages\PackageCompiler\BBtC7\src\api.jl:1
04 [inlined] (repeats 2 times)
 [11] top-level scope at none:0

Gtk is installed and works when I run the code, don’t know why there is a LoadError.
I am not sure how to use Base.@ccallable function julia_main(ARGS::Vector{String})::Cint specified in the README?

Hope you can help?

I’m doing this on macOS, it works with ApplicationBuilder.

using Gtk, ...

Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
    
    #my Gtk code

    c = Condition()
    signal_connect(win, :destroy) do widget
        notify(c)
    end
    wait(c)#wait until we are done with out window
end

That said getting redistributable Gtk softwares might require a bit more work, because you need to bundle the libraries with the application and fix some paths issues (Julia often use absolute paths, so the application won’t work if it’s not in the same directory).

I’ve got a working version on macOS but I’m not sure how Gtk libraries are installed on Windows (I have an issue here about it, but I need to update it).

2 Likes

Oh I see. Thanks for your reply @jonathanBieler!