I’m trying to learn how to write bindings using C-Types. As a project I’m writing bindings for tree-sitter (I am aware of the existence of reason-tree-sitter, I’m just writing my own for fun).
When I try to load my library in utop, i get Fatal error: exception Dl.DL_error("dlsym(RTLD_DEFAULT, ts_new_parser): symbol not found").
I’m kinda navigating blindly there. I’m following the beautiful real-world-ocaml example, but it’s linking a globally installed c library, and I’m trying to specify the lib and include paths myself.
Or maybe you can pass -l$(LIB) to ocamlmklib (note, not via -cclib), I think that this put C code in the stub library dll, see here. Mentioning the archive directly on the cli might also work.
Ok so first, I didn’t know that I couldn’t statically link for toplevel just like that, but it makes sense
I am no really trying to build for toplevel I was just trying to see if it works. I want to build statically for a binary now, but I still get this Fatal error: exception Dl.DL_error("dlsym(RTLD_DEFAULT, ts_new_parser): symbol not found").
If I pass -l$(LIB) to ocamlmklib (through c_library_flags, as follows), I still get the DL_error.
It’s difficult to investigate the problem without seing the actual invocations. But trying to make it first work on an executable (rather than in the toplevel) is a good idea.
Ok, so I simply added the -static flag, and ended up with the ld: library not found for -lcrt0.o.
Grom another answer of yours on this forum, I understand that I just can’t do that on MacOs.
Statically linking by passing with -static to gcc on macOS has been “forbidden” for quite some time.
May not be the best idea (if multiple libs do that for the same lib) but your problem should remain solvable by passing the archive directly on the cli to have them in the stub library that is used by ocamlrun.