Hi
I am trying to call OCaml functions from C code. I followed exactly the example given in the documentation Chapter 20 Interfacing C with OCaml (with the ocamlc
version) but the compilation of the main C program fails with the error at the bottom of this message.
I am using OCaml 4.09.1 (installed with opam in a directory that I call /path/to/switch
in the error message below) under Linux Debian.
Thanks for your help!
Error message:
$ cc -o prog -I `ocamlc -where` main.c mod.a -lcurses
/usr/bin/ld: mod.a(floats_b.o): in function `caml_exp_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:463:(.text+0xbf9): undefined reference to `exp'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_round':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:483:(.text+0xd79): undefined reference to `round'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_nextafter':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:517:(.text+0xecd): undefined reference to `nextafter'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_fma':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:543:(.text+0xf61): undefined reference to `fma'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_fmod_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:744:(.text+0x1081): undefined reference to `fmod'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_log_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:774:(.text+0x1269): undefined reference to `log'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_log10_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:779:(.text+0x12e9): undefined reference to `log10'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_sqrt_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:799:(.text+0x159d): undefined reference to `sqrt'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_power_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:804:(.text+0x15bd): undefined reference to `pow'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_sin_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:809:(.text+0x1639): undefined reference to `sin'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_sinh_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:814:(.text+0x16b9): undefined reference to `sinh'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_cos_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:819:(.text+0x1739): undefined reference to `cos'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_cosh_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:824:(.text+0x17b9): undefined reference to `cosh'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_tan_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:829:(.text+0x1839): undefined reference to `tan'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_tanh_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:834:(.text+0x18b9): undefined reference to `tanh'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_asin_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:839:(.text+0x1939): undefined reference to `asin'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_acos_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:844:(.text+0x19b9): undefined reference to `acos'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_atan_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:849:(.text+0x1a39): undefined reference to `atan'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_atan2_float':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:854:(.text+0x1abd): undefined reference to `atan2'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_hypot':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:865:(.text+0x1c0d): undefined reference to `hypot'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_expm1':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:890:(.text+0x1ca9): undefined reference to `expm1'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_log1p':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:904:(.text+0x1d29): undefined reference to `log1p'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_round':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:483:(.text+0xd61): undefined reference to `round'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_nextafter':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:517:(.text+0xeb1): undefined reference to `nextafter'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_fma':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:543:(.text+0xf41): undefined reference to `fma'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_hypot':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:865:(.text+0x1bf1): undefined reference to `hypot'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_expm1':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:890:(.text+0x1c81): undefined reference to `expm1'
/usr/bin/ld: mod.a(floats_b.o): in function `caml_log1p':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/floats.c:904:(.text+0x1c91): undefined reference to `log1p'
/usr/bin/ld: mod.a(major_gc_b.o): in function `caml_major_collection_slice':
/path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/major_gc.c:820:(.text+0x11a2): undefined reference to `fmin'
/usr/bin/ld: /path/to/switch/.opam-switch/build/ocaml-base-compiler.4.09.1/runtime/major_gc.c:739:(.text+0x13f3): undefined reference to `fmin'
collect2: error: ld returned 1 exit status