# PackageCompiler and modules

**URL:** <https://discourse.julialang.org/t/packagecompiler-and-modules/19973>\
**Category:** General Usage\
**Tags:** module, compilation, scope\
**Created:** [January 23, 2019, 10:56am UTC](https://discourse.julialang.org/t/packagecompiler-and-modules/19973 "2019-01-23T10:56:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![plapplop](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@plapplop](https://discourse.julialang.org/u/plapplop)\
**Post date:** [January 23, 2019, 10:56am UTC](https://discourse.julialang.org/t/packagecompiler-and-modules/19973/1 "2019-01-23T10:56:05Z")

</div>

I’m trying to compile an old Julia 0.6 code of mine with `PackageCompiler` and I’m running into trouble with the following situation:

```julia
module M
type A a end
export A
end

using M

Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
    a = A(1.0) ## works
    path1 = string(@ __DIR__ , "/file1.jl")
    path2 = string(@ __DIR__ , "/file2.jl")
    file1 = open(path1, "w")
    write(file1, "type B field::M.A end")
    close(file1)
    file2 = open(path2, "w")
    write(file2, "type B field::A end")
    close(file2)
    include(path1) ## works
    include(path2) ## fails
    return 0
end

```

I can use `A` fine in `julia_main` if calling it directly. Loading `file1.jl` works but not `file2.jl`, I get the following error:

```julia
fatal: error thrown and no exception handler available.
LoadError(at "/Users/plppplp/.julia/v0.6/PackageCompiler/examples/file2.jl" line 1: UndefVarError(var=:A))
rec_backtrace at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
jl_throw at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
jl_undefined_var_error at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
eval at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
do_call at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
eval at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
eval at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
eval_body at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
jl_toplevel_eval_body at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
jl_toplevel_eval_flex at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
jl_parse_eval_all at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
jl_load_ at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/libjulia.dylib (unknown line)
include_from_node1 at /Users/plppplp/.julia/v0.6/PackageCompiler/builddir/module.dylib (unknown line)
jlcall_include_from_node1_1175 at /Users/plppplp/.julia/v0.6/PackageCompiler/builddir/module.dylib (unknown line)
include at /Users/plppplp/.julia/v0.6/PackageCompiler/builddir/module.dylib (unknown line)
julia_main at /Users/plppplp/.julia/v0.6/PackageCompiler/builddir/module.dylib (unknown line)
julia_main at /Users/plppplp/.julia/v0.6/PackageCompiler/builddir/module.dylib (unknown line)
main at /Users/plppplp/.julia/v0.6/PackageCompiler/./builddir/module (unknown line)

```

In practice module `M` is huge and I can’t really afford to specify `M.` in front of all variables from module `M` in included files. This code worked fine without using `PackageCompiler`. Is there any way to make `PackageCompiler` understand I’m referring to variables from module `M`…?

Many thanks!

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [January 23, 2019, 11:15am UTC](https://discourse.julialang.org/t/packagecompiler-and-modules/19973/2 "2019-01-23T11:15:35Z")

</div>

What happens if you add `using M;` in `file2.jl` and, alternatively, if you rename of `B` to something else ?

---

<div class="post-metadata">

**Author:** ![plapplop](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@plapplop](https://discourse.julialang.org/u/plapplop)\
**Post date:** [January 23, 2019, 11:39am UTC](https://discourse.julialang.org/t/packagecompiler-and-modules/19973/3 "2019-01-23T11:39:24Z")

</div>

Thanks for the suggestion! I should have tried it by myself… So yes, `using M` at the beginning of each included file seems to work. I’m currently trying to figure out if this is a viable option for my project, but I think it will be.

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [January 23, 2019, 12:23pm UTC](https://discourse.julialang.org/t/packagecompiler-and-modules/19973/4 "2019-01-23T12:23:43Z")

</div>

I am not sure why that works, glad that it does 🙂 It may be that when compiling, scoping rules change a bit… It may be a limitation or bug.
