Search code examples
macosocamlctypeslibffi

Undefined symbols for mac ocaml build


I've been trying to compile a recent application that uses ctypes and sqlexpr, but I'm having trouble with symbols not being resolved. I built ctypes and sqlexpr from OPAM, and have updated versions of libffi from brew, but don't understand why I might not be getting the correct library linkage. Anyone care to take a guess? (I've already tried my typical fix for this, which is to pass in CFLAGS="-arch i386")

Undefined symbols for architecture x86_64:
  "_ffi_closure_alloc", referenced from:
      _ctypes_make_function_pointer in libctypes-foreign-base_stubs.a(ffi_call_stubs.o)
  "_ffi_prep_closure_loc", referenced from:
      _ctypes_make_function_pointer in libctypes-foreign-base_stubs.a(ffi_call_stubs.o)
  "_sqlite3_enable_load_extension", referenced from:
      _caml_sqlite3_enable_load_extension in libsqlite3_stubs.a(sqlite3_stubs.o)
     (maybe you meant: _caml_sqlite3_enable_load_extension)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "_none_", line 1:
Error: Error while building custom runtime system
Command exited with code 2.
Compilation unsuccessful after building 41 targets (40 cached) in 00:00:00.
make: *** [all] Error 10

Solution

  • From https://github.com/ocaml/opam-repository/issues/398, looks like this is a problem with the sqlite on Mac OS X 10.7.5.

    "switching the order in which packages are specified resolves the issue"