简体   繁体   中英

Building llvm bindings with ocamlbuild in Ocaml

I could build and install LLVM, and ocaml bindings libraries are in /usr/local/llvm/lib/ocaml directory. 在此处输入图片说明

When building in example ( http://llvm.org/docs/tutorial/OCamlLangImpl3.html ), I tried ocamlbuild toy.byte as in instruction to get error message.

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.

It looks like LLVM libraries are not found. How to teach ocaml to find one?

I have myocamlbuild.ml to have this content:

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

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

I also tried with ocamlbuild toy.byte -pkg llvm to get this error.

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

I use Mac OS X 10.7 and installed ocaml with brew.

要使用-package的选项ocamlbuild ,你必须通过附加-use-ocamlfind选项: ocamlbuild -use-ocamlfind toy.byte -package llvm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM