无法在ocaml中打开Llvm [英] Can't open Llvm in ocaml

查看:109
本文介绍了无法在ocaml中打开Llvm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ocaml中使用llvm绑定,在我的文件test.ml中,我只有一行代码:

I'm trying to use llvm binding in ocaml, in my file test.ml, I have one line of code:

open Llvm

当我运行命令

ocamlbuild -use-ocamlfind test.byte -package llvm

我得到这个结果:

+ ocamlfind ocamldep -package llvm -modules test.ml > test.ml.depends
ocamlfind: Package `llvm' not found
Command exited with code 2.
Compilation unsuccessful after building 1 target (0 cached) in  00:00:00.

我在这方面做错了什么?谢谢.

What did I do wrong in this? Thanks.

顺便说一句,_tag文件包含:

BTW, the _tag file contains:

"src": traverse
<src/{lexer,parser}.ml>: use_camlp4, pp(camlp4of)
<*.{byte,native}>: g++, use_llvm, use_llvm_analysis

myocamlbuild.ml包含:

myocamlbuild.ml contains:

open Ocamlbuild_plugin;;
ocaml_lib ~extern:true "llvm";;
ocaml_lib ~extern:true "llvm_analysis";;
flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++"]);;

推荐答案

我不知道您使用的指令为何如此复杂.如果您已通过opam安装了LLVM绑定,则无需进行任何此类操作即可在OCaml中使用llvm绑定.

I don't know why the instructions that you're using are so complex. You don't have to do anything like this to use llvm bindings in OCaml, provided you have installed them via opam.

这是食谱:

它可能很简单

opam install llvm

但是,opa​​m可能会尝试安装系统上不可用的最新版本,因此请选择您拥有的特定版本,然后执行以下操作(假设您拥有llvm-3.8):

However, opam may try to install the latest version that is not available on your system, so pick a particular version, that you have and do the following (suppose you have llvm-3.8):

opam install conf-llvm.3.8
opam install llvm --criteria=-changed

(-criteria标志将阻止opam将conf-llvm升级到最新版本)

(The -criteria flag will prevent opam from upgrading conf-llvm to the newest version)

一旦成功,您就可以轻松地编译程序,而无需任何额外的脚手架.

Once it succeeds, you can easily compile your programs without any additional scaffolding.

  1. 创建一个全新的文件夹,例如

  1. create a fresh new folder, e.g.,

mkdir llvm-project
cd llvm-project

  • 创建一个示例应用程序(从我在网上找到的一些教程中借来的):

  • create a sample application (borrowed from some tutorial, that I've found online):

    cat >test.ml<<EOF
    open Llvm
    
    let _ =
      let llctx = Llvm.global_context () in
      let llmem = Llvm.MemoryBuffer.of_file Sys.argv.(1) in
      let llm = Llvm_bitreader.parse_bitcode llctx llmem in
      Llvm.dump_module llm ;
      ()
    EOF
    

  • 将其编译为字节码

  • compile it for bytecode

    ocamlbuild -pkgs llvm,llvm.bitreader test.byte
    

    或本地代码

    ocamlbuild -pkgs llvm,llvm.bitreader test.native
    

  • 运行

  • run it

    ./test.native mycode.bc
    

  • 这篇关于无法在ocaml中打开Llvm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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