Julia 未定义从并行文件夹导入

问题描述 投票:0回答:0

我无法导入模块并使用它。加载的文件被声明为未定义。我正在从 bar 调用 foo 中的一个函数。错误是什么?

ERROR: UndefVarError: foo not defined
Stacktrace:
 [1] callFoo()
   @ Main.bar filepath
\pkg2\bar.jl:6
 [2] top-level scope
   @ filepath\main.jl:4

文件夹结构如下:

root
   main.jl
   pkg1
       foo.jl
   pkg2
       bar.jl

main.jl

include("./pkg2/bar.jl")

bar.callFoo()

foo.jl

module foo

function mul2(val::Int)
    return val*2
end

end 

bar.jl

include("../pkg1/foo.jl")

module bar

function callFoo()
    val1 = foo.mul2(2)
    println(val1)
end

end
import julia include using
© www.soinside.com 2019 - 2024. All rights reserved.