How do I statically link some .a
files with Dune? How do I write my OCaml bindings to them?
Background
I’m creating an OCaml libsql client. To interface with libsql, I’m taking the same approach as their Go client where the client statically links precompiled native client libs for libsql. Go has the ability to link archive files, and with cgo, automatically generate bindings to the c api. You can see how it’s done here in Go.
Attempt so far
I want to take the same approach with dune. I have copies of the precompiled libs. In my dune file, I’ve included the macos-specific lib via dune’s foreign_archives API. Because I haven’t learned how to conditionally build for different archs and systems, my dune file references just the macos lib for expediency.
I have some ctypes bindings to the libsql.h header file.
I also have a test to execute my bindings. On test run, I encounter an error where I’m unable to find the symbols. It looks like dune is still expecting the libsql bindings to be dynamically loaded. What am I missing?
$ dune runtest
File "test/dune", line 2, characters 7-18:
2 | (name test_libsql)
^^^^^^^^^^^
Fatal error: exception Dl.DL_error("dlsym(RTLD_DEFAULT, libsql_enable_internal_tracing): symbol not found")
My dune file
(library
(name libsql)
(modes native)
(public_name libsql)
(modules libsql libsql_bindings)
(libraries ctypes ctypes.foreign)
(foreign_archives libsql_macosx_arm64))
I’m quite unfamiliar with dynamic/static linking in general.