[ocaml-ctypes] linking with non-standard C library

Ashish Agarwal agarwal1975 at gmail.com
Tue Oct 1 21:52:21 BST 2013


I've managed to compile the ncurses example with the following commands:

ncurses_cmd.native: ncurses.ml ncurses.mli ncurses_cmd.ml
 ocamlfind ocamlc -c -g -annot -package unix,threads,bigarray -thread -o
ncurses.cmi ncurses.mli
ocamlfind ocamlopt -c -g -annot -package
unix,threads,bigarray,ctypes,ctypes.foreign -thread -o ncurses.cmx
ncurses.ml
 ocamlfind ocamlopt -a -cclib -lncurses ncurses.cmx -o ncurses.cmxa
ocamlfind ocamlopt -c -g -annot -package unix,threads,bigarray -thread -o
ncurses_cmd.cmx ncurses_cmd.ml
 ocamlfind ocamlopt -g -linkpkg -package
unix,threads,bigarray,ctypes,ctypes.foreign -thread ncurses.cmxa
ncurses_cmd.cmx -o ncurses_cmd.native


Now, I'm trying to mimic this to wrap a library that is not in my system's
default location. A couple of questions:

* What is the recommended way to package this? Should I include the source
of the external C library within my OCaml repo?

* What options do I have to use to link in a library in a custom location?
I've tried every variation of -cclib, -ccopt -L/path/to/lib, -linkall, and
am just guessing at this point. No matter what, I always get this error:

Fatal error: exception Dl.DL_error("dlsym(RTLD_DEFAULT, sam_open): symbol
not found")
Raised at file "src/dl.ml", line 42, characters 26-44
Called from file "src/foreign.ml", line 18, characters 25-53
Called from file "samtools.ml", line 4, characters 15-60

However, I'm pretty sure "sam_open" is exported by the library I'm using:

$ nm libbam.a | grep sam_open
0000000000000060 T _sam_open
0000000000005cf0 S _sam_open.eh
                 U _sam_open
                 U _sam_open
                 U _sam_open
                 U _sam_open
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/ctypes/attachments/20131001/a76e563c/attachment.html>


More information about the Ctypes mailing list