如何编译 Julia 脚本? [英] How to compile a julia script?

查看:21
本文介绍了如何编译 Julia 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到 0.4.* 版本的 julia 有一个 --compile 选项.

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

奇怪的是,我找不到任何关于它的文档.

Strangely, I cannot find any documentation about it.

我正在尝试(在 Ubuntu 中)将 julia 脚本编译为可执行的 LLVM 字节码文件.但是直到这里,我都失败了:

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

如果我将 boot.jl 文件放在同一文件夹中,此错误将不再出现.

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

我应该如何将 julia 脚本编译为可执行/混淆字节码?

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

仅供参考,我的 test.jl 文件仅包含 print(123)

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

推荐答案

这是一个示例,来自 OS X 上的 julia 源代码,/tmp/test.jl 为:

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

function foo()
    print(123)
end

precompile(foo, ())

julia/base/userimg.jlinclude("/tmp/test.jl")

julia/base 目录中执行以下命令:

Execute the following inside the julia/base directory:

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

然后运行 ​​llvm-dis test.bc -o test.ll.在(巨大的)图像中的某处,我们有测试函数的相关字节码:

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 
...

也就是说,截至目前(2015 年 12 月),Julia 不能用于提前编译独立的可执行文件.但是,以下内容可能会引起您的兴趣:

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

这篇关于如何编译 Julia 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆