Installing ocaml API for Z3 using opam

。_饼干妹妹 提交于 2019-12-02 01:10:38

TL;DR; The package is broken. The fix and a couple of workarounds are below, but in general, such questions should be posted to corresponding issue trackers. So consider opening an issue report or pull request with a fix.

Those linker errors indicate that the symbols from the C++ standard library are missing. Since OCaml is using the C linker to link the final product it is not passing the C++ standard library by default. Of course, a properly made package should do this for us1, but we can still do it manually via the -cclib -lstdc++ (if you have libstdc++, otherwise use -lc++).

ocamlfind ocamlopt -linkpkg -cclib -lstdc++ -package z3 example.ml -o exe

With ocamlbuild you can use the cclib(x) parametrized tag, e.g.,

 <example.ml>: cclib(-lstdc++)

A note for the dune users

TL;DR; If you're using dune then you still have to add (flags (-cclib -lstdc++)) to your library/executable stanza, since dune is ignoring linkopts (and many other fields of the META files).

Long story. The META file specification is defined and implemented by the findlib library. The dune building system is not using findlib, instead they have re-implemented a small subset of findlib with many features missing, namely fields like linkopts and predicates. That's why you still need to add this field, despite the fact, that META prescribes it. At least as of October 2019.


1 the provided META file contains a bogus

linkopts = "-cclib -L/usr/lib"

which (a) doesn't make sense since -L is not a linker option, but the compiler one, and (b) is useless, as /usr/lib is usually in the search path anyway.

The correct option should be:

linkopts = "-cclib -lstdc++"

You might edit the file directly, it is located at $(ocamlfind query z3)/META.

Please, consider submitting a fix either to OPAM package or (ideally) to z3.

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