# Correct usage of build\_sysimg

**URL:** https://discourse.julialang.org/t/correct-usage-of-build-sysimg/27457
**Category:** General Usage
**Created:** [August 12, 2019, 1:25pm UTC](https://discourse.julialang.org/t/correct-usage-of-build-sysimg/27457 "2019-08-12T13:25:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fverdugo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fverdugo/32/9446_2.png) [@fverdugo](https://discourse.julialang.org/u/fverdugo)
#### Post date: [August 12, 2019, 1:25pm UTC](https://discourse.julialang.org/t/correct-usage-of-build-sysimg/27457/1 "2019-08-12T13:25:39Z")

</div>

I am unable to build a system image using the `build_sysimg` command. I get different types of errors.

Assume that I want to build a system with the following user definitions:

```julia
# file userimg.jl
function bar()
  println("Hi bar!")
end

@generated function foo(x::T) where T
  println("Compiling foo function for type $T")
  quote
    x
  end
end

# Force compilation
bar()
foo(1)

```

Then, following the docuentation in [System Image Building · The Julia Language](https://docs.julialang.org/en/v1/devdocs/sysimg/index.html)  
I try to build the system image as follows:

```julia
$ julia ~/Apps/julia/julia-1.1.0-linux-x86_64/julia-1.1.0/share/julia/build_sysimg.jl ./sys native ./userimg.jl
ERROR: LoadError: UndefVarError: Libdl not defined
Stacktrace:
 [1] #build_sysimg#3(::Bool, ::Bool, ::Function, ::String, ::String, ::String) at /home/verdugo/Apps/julia/julia-1.1.0-linux-x86_64/julia-1.1.0/share/julia/build_sysimg.jl:33
 [2] (::getfield(Main, Symbol("#kw##build_sysimg")))(::NamedTuple{(:force, :debug),Tuple{Bool,Bool}}, ::typeof(build_sysimg), ::String, ::String, ::String) at ./none:0
 [3] top-level scope at /home/verdugo/Apps/julia/julia-1.1.0-linux-x86_64/julia-1.1.0/share/julia/build_sysimg.jl:209
 [4] include at ./boot.jl:326 [inlined]
 [5] include_relative(::Module, ::String) at ./loading.jl:1038
 [6] include(::Module, ::String) at ./sysimg.jl:29
 [7] exec_options(::Base.JLOptions) at ./client.jl:267
 [8] _start() at ./client.jl:436
in expression starting at /home/verdugo/Apps/julia/julia-1.1.0-linux-x86_64/julia-1.1.0/share/julia/build_sysimg.jl:187

```

Seems to be a missin `using Libdl`, right? So I try to load `Libdl` and run the command, but I get another error:

```julia
verdugo@debian:~/Code/jl/tests/userimg$ julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.1.0 (2019-01-21)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> include(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "build_sysimg.jl"))

julia> using Libdl

julia> build_sysimg("sys","native","userimg.jl")
ERROR: UndefVarError: info not defined
Stacktrace:
 [1] (::getfield(Main, Symbol("##4#5")){Bool,String,String})() at /home/verdugo/Apps/julia/julia-1.1.0-linux-x86_64/julia-1.1.0/share/julia/build_sysimg.jl:74
 [2] cd(::getfield(Main, Symbol("##4#5")){Bool,String,String}, ::String) at ./file.jl:96
 [3] #build_sysimg#3(::Bool, ::Bool, ::Function, ::String, ::String, ::String) at /home/verdugo/Apps/julia/julia-1.1.0-linux-x86_64/julia-1.1.0/share/julia/build_sysimg.jl:48
 [4] build_sysimg(::String, ::String, ::String) at /home/verdugo/Apps/julia/julia-1.1.0-linux-x86_64/julia-1.1.0/share/julia/build_sysimg.jl:28
 [5] top-level scope at none:0

```

Can somebody tell me what I am doing wrong? Thanks for the help!

---

<div class="post-metadata">

### Author: ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)
#### Post date: [August 12, 2019, 1:31pm UTC](https://discourse.julialang.org/t/correct-usage-of-build-sysimg/27457/2 "2019-08-12T13:31:03Z")

</div>

[https://github.com/JuliaLang/julia/issues/28557](https://github.com/JuliaLang/julia/issues/28557) suggests that this is a known issue and the docs should be adjusted to point to PackageCompiler.jl instead of the method in the manual.

---

<div class="post-metadata">

### Author: ![fverdugo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fverdugo/32/9446_2.png) [@fverdugo](https://discourse.julialang.org/u/fverdugo)
#### Post date: [August 12, 2019, 1:34pm UTC](https://discourse.julialang.org/t/correct-usage-of-build-sysimg/27457/3 "2019-08-12T13:34:59Z")

</div>

Good to know. Thanks!
