ocaml - 对“caml_names_of_builtin_cprim”的未定义引用
问题描述
我正在尝试编译一个独立于 Ocaml 本身使用 OCaml GC 的小型 C 程序。
编码:
#include <caml/mlvalues.h>
#include <caml/memory.h>
void foo(value v1, value v2, value v3)
{
CAMLparam3 (v1, v2, v3);
CAMLreturn0;
}
编译:
gcc -L/usr/lib/ocaml -lcamlrun -lm -ldl -lcamlstr src/benchmarks/binarytrees-escaped.c
输出:
/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
知道我缺少哪个图书馆吗?我已经尝试了我可以在系统上找到的所有库(不使用或不包括 opam):
/usr/lib/ocaml/libcamlrun.a
/usr/lib/ocaml/libcamlrun_pic.a
/usr/lib/ocaml/libcamlrun_shared.so
/usr/lib/ocaml/libcamlstr.a
安装的 OCaml 是:
$ which ocaml
/usr/bin/ocaml
$ ocaml -version
The OCaml toplevel, version 4.02.3
解决方案
通过包含来自 OCaml 编译器的虚拟对象文件来解决,需要使链接的 OCaml 运行时工作:
ocamlopt -output-obj -o test.o dummy.ml
cc src/benchmarks/binarytrees-escaped.c test.o -L`ocamlc -where` -lasmrun -lm -ldl
dummy.ml 仅包含let i = 10
(但似乎也可以为空)。
推荐阅读
- python - 使用 Sphinx Autodoc 的漂亮打印特殊方法
- java - ExitStatus 2 当我使用 JSCH 通过 SSH 运行命令时
- javascript - 按下按钮后获取段落文本并将其传递给 javascript 函数
- java - 如何从本地 Maven 存储库中删除工件版本
- c - 为什么变量在比较时会变为零?
- android - 将汉堡图标动画化为工具栏中的箭头
- java - 使用 statement.executeQuery 编写的选择语句无法选择具有 - (破折号)的值
- c# - 如果在 Try Catch C# 中未捕获到异常,则显示另一条消息
- c++ - 编译时字符串异或的问题
- unity3d - Unity-Vuforia 多屏幕空间画布问题