I'm trying to compile a tiny C program that uses the OCaml GC independently of Ocaml itself.
The code:
#include <caml/mlvalues.h>
#include <caml/memory.h>
void foo(value v1, value v2, value v3)
{
CAMLparam3 (v1, v2, v3);
CAMLreturn0;
}
Compiling with:
gcc -L/usr/lib/ocaml -lcamlrun -lm -ldl -lcamlstr src/benchmarks/binarytrees-escaped.c
Output:
/usr/lib/ocaml/libcamlrun.a(startup.o): In function `caml_main':
(.text+0x62c): undefined reference to `caml_names_of_builtin_cprim'
/usr/lib/ocaml/libcamlrun.a(startup.o): In function `caml_main':
(.text+0x6b2): undefined reference to `caml_names_of_builtin_cprim'
/usr/lib/ocaml/libcamlrun.a(dynlink.o): In function `caml_build_primitive_table':
(.text+0x2aa): undefined reference to `caml_builtin_cprim'
/usr/lib/ocaml/libcamlrun.a(dynlink.o): In function `caml_build_primitive_table':
(.text+0x2ba): undefined reference to `caml_names_of_builtin_cprim'
/usr/lib/ocaml/libcamlrun.a(dynlink.o): In function `caml_build_primitive_table':
(.text+0x338): undefined reference to `caml_names_of_builtin_cprim'
/usr/lib/ocaml/libcamlrun.a(dynlink.o): In function `caml_build_primitive_table_builtin':
(.text+0x3ad): undefined reference to `caml_builtin_cprim'
/usr/lib/ocaml/libcamlrun.a(dynlink.o): In function `caml_build_primitive_table_builtin':
(.text+0x3cf): undefined reference to `caml_builtin_cprim'
collect2: error: ld returned 1 exit status
Any idea which library I'm missing? I've tried with all libs I could find on the system (not using or including opam):
/usr/lib/ocaml/libcamlrun.a
/usr/lib/ocaml/libcamlrun_pic.a
/usr/lib/ocaml/libcamlrun_shared.so
/usr/lib/ocaml/libcamlstr.a
The installed OCaml is:
$ which ocaml
/usr/bin/ocaml
$ ocaml -version
The OCaml toplevel, version 4.02.3
question from:
https://stackoverflow.com/questions/65910143/undefined-reference-to-caml-names-of-builtin-cprim 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…