在Ocaml中使用ocamlbuild构建llvm绑定

时间:2014-01-02 19:35:58

标签: macos binding ocaml llvm

我可以构建和安装LLVM,ocaml绑定库位于/usr/local/llvm/lib/ocaml目录中。 enter image description here

在示例(http://llvm.org/docs/tutorial/OCamlLangImpl3.html)中构建时,我在指令中尝试ocamlbuild toy.byte以获取错误消息。

a@prosseek Chapter3> ocamlbuild toy.byte
Finished, 0 targets (0 cached) in 00:00:00.
+ /usr/local/bin/ocamlc.opt -c -o codegen.cmo codegen.ml
File "codegen.ml", line 5, characters 0-9:
Error: Unbound module Llvm
Command exited with code 2.
Compilation unsuccessful after building 10 targets (9 cached) in 00:00:00.

看起来没有找到LLVM库。如何教ocaml找一个?

我有myocamlbuild.ml来获取此内容:

open Ocamlbuild_plugin;;
ocaml_lib ~extern:true "llvm";;
ocaml_lib ~extern:true "llvm_analysis";;

flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++"]);;

我还尝试使用ocamlbuild toy.byte -pkg llvm来解决此错误。

Warning: tag "package" does not expect a parameter, but is used with parameter "llvm"
+ /usr/local/bin/ocamlc.opt -c bindings.c
clang: warning: argument unused during compilation: '-fno-defer-pop'
+ /usr/local/bin/ocamlc.opt llvm.cma llvm_analysis.cma llvm_executionengine.cma llvm_target.cma llvm_scalar_opts.cma -cc g++ -I /Users/smcho/.opam/system/lib/llvm/. '-ccopt -lstdc++' llvm.cma ast.cmo codegen.cmo token.cmo lexer.cmo parser.cmo toplevel.cmo toy.cmo bindings.o -o toy.byte
/usr/local/bin/ocamlc.opt: unknown option `-ccopt -lstdc++'.
Usage: ocamlc <options> <files>
Options are:
.. 

我使用Mac OS X 10.7并使用brew安装了ocaml。

1 个答案:

答案 0 :(得分:2)

要使用-package的{​​{1}}选项,您必须传递额外的ocamlbuild选项:-use-ocamlfind