When trying to link a complete object file with a C program, this is what I get for ocaml 4.06
:
dune build app.exe.o
clang -o main -I /Users/rauan/.opam/workspace/lib/ocaml main.c _build/default/app.exe.o
Undefined symbols for architecture x86_64:
"_caml_code_area_end", referenced from:
_segv_handler in app.exe.o
"_caml_code_area_start", referenced from:
_segv_handler in app.exe.o
"_caml_main", referenced from:
_main in main-7906c3.o
(maybe you meant: _caml_main_argv)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
Upgrading ocaml to 4.07
reduces the errors amount down to only _caml_code_area_end
being undefined. (I’m guessing that GPR#1740 helped with that)
I made a sample repo to reproduce the issue: https://github.com/rauanmayemir/linking-example
The reason it’s organized that way is because I want to keep my bindings and ocaml logic separate from the main program. (I then intend to have e.g an XCode project target with platform-specific assets and call out my ocaml logic from there)
It happens when I try to link an object file built in dune’s object
linking mode (here’s the build log).
Note: I can successfully execute object file built in exe
linking mode (without linking it to main.c and preliminarily dropping the callback register and running the code directly instead).
Please help me understand whether I’m doing something wrong or there’s a bug in ocaml
.