Linking Error with External C Code in Library

This command line does not actually embed stuff_external.o into library.a, it just records the name of the object file in library.cmxa so that it is automatically added to the command line during the linking step (see next paragraph).

In order for the compiler to locate stuff_external.o during this linking step you need to add -I library, so that the final command line could be

ocamlopt -I library library.cmxa main.cmx -o program

Incidentally, if you are able to, it may be a good idea to use Dune, it includes a lot of logic to make creating C stubs rather painless.

Cheers,
Nicolas

1 Like