在学习Julia时,我偶然发现了一个基本任务,即包含来自不同目录的文件。我有两个目录,
核心
和
,两者均不是另一方的母公司;请参见图。目录
核心
有档案
具有
module Core
foo() = 1
end
或者它可以是一个基本的
.jl
文件,而不是模块,具有
foo()
.
档案
,在目录中
,需要使用
foo()
从…起
. 所以我试着把下面几行放进
Explore.jl
:
/Users/me/PycharmProjects/juliaProjects/src/Core/Core.jl
,
include("./Core.jl")
和其他排列。然而,我不断地犯这样的错误
ERROR: LoadError: could not open file /Users/me/PycharmProjects/juliaProjects/src/Core/Core.jl
Stacktrace:
[1] include at ./boot.jl:317 [inlined]
[2] include_relative(::Module, ::String) at ./loading.jl:1038
[3] include(::Module, ::String) at ./sysimg.jl:29
[4] include(::String) at ./client.jl:398
[5] top-level scope at none:0
[6] include at ./boot.jl:317 [inlined]
[7] include_relative(::Module, ::String) at ./loading.jl:1038
[8] include(::Module, ::String) at ./sysimg.jl:29
[9] exec_options(::Base.JLOptions) at ./client.jl:239
[10] _start() at ./client.jl:432
in expression starting at /Users
什么是正确的答案
include
jl。
在Mac OS High Sierra上的环境是Julia 0.7。请注意,我使用的不是shell,而是IDE,即Intellij 2018.3的julia插件0.3.3。
我查了其他问题,如
loading a module from the local directory in Julia
How to import custom module in julia
,
What should path be to Julia source file?
,但它们似乎不起作用。
编辑:
根据接受的答案,文件
Explore.jl
应包括
cd("src/Core")
include("../Core/Core.jl")