How to compile a julia script?

六月ゝ 毕业季﹏ 提交于 2019-12-12 08:20:31

问题


I have noticed that the version 0.4.* of julia has a --compile option.

Strangely, I cannot find any documentation about it.

I was trying (in Ubuntu), to compile a julia script to an executable LLVM bytecode file. But until here, I failed:

julia --compile=yes --output-bc test.bc test.jl
Segmentation fault (core dumped)

I also can get this error message:

julia --compile=yes --output-bc test.bc test.jl
ERROR: could not open file boot.jl

This error does not appear anymore, if I put a boot.jl file in the same folder.

How should I do to compile a julia script to an executable/obfuscated bytecode ?

Edit: FYI, my test.jl file contains only print(123)


回答1:


Here's an example, from a julia source build on OS X, with /tmp/test.jl as:

function foo()
    print(123)
end

precompile(foo, ())

And julia/base/userimg.jl as include("/tmp/test.jl")

Execute the following inside the julia/base directory:

julia --compile=yes --output-bc test.bc -J ../usr/lib/julia/inference.ji sysimg.jl

Then run llvm-dis test.bc -o test.ll. Somewhere in the (enormous) image we have the relevant bytecode for the test function:

define internal %jl_value_t* @julia_foo_22542() {
top:
  %0 = alloca [4 x %jl_value_t*], align 8, !dbg !51528 
...

That said, as of now (Dec. 2015), Julia is not usable for ahead-of-time compilation of stand-alone executables. However, the following may be of interest:

  • https://github.com/dhoegh/BuildExecutable.jl (doesn't use --output-bc, as yet, but has a nicer user interface and that option would be easy to add)
  • https://github.com/JuliaLang/julia/pull/13677


来源:https://stackoverflow.com/questions/34146968/how-to-compile-a-julia-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!