我正在研究一些混合了OCaml和C的代码,函数caml_release_runtime_system()
和caml_acquire_runtime_system()
是在OCaml 3.12中引入的(在早期版本中它们被称为其他东西)但我希望兼容如果可能的话,回到3.10,我可以使用#ifdef
吗?我查看了标题(在我的Debian系统中的/usr/lib/ocaml/caml
中)并且找不到任何看起来可能的内容。谢谢!
更新:这就是我所做的
这就是我所做的:
#if OCAML_VERSION_MINOR >= 12
#include <caml/threads.h>
#else
#include <caml/signals.h>
#endif
#ifndef caml_acquire_runtime_system
#define caml_acquire_runtime_system caml_leave_blocking_section
#define caml_release_runtime_system caml_enter_blocking_section
#endif
答案 0 :(得分:3)
ocamlopt
和ocamlc
二进制文件支持-vnum
and -version
switches获取版本号:
-vnum或-version 以简短格式打印编译器的版本号(例如3.11.0),然后退出。
3.12.0支持此开关,文档中的示例文本表明3.11.0也支持它。我没有3.10.0方便,但 nlucaroni (其OCaml Fu看起来比我强)在评论中指出3.10.0确实有ocamplopt -version
。
所以你可以在你的Makefile中添加这样的东西:
OCAML_VERSION_MAJOR = `ocamlopt -version | cut -f1 -d.`
OCAML_VERSION_MINOR = `ocamlopt -version | cut -f2 -d.`
OCAML_VERSION_POINT = `ocamlopt -version | cut -f3 -d.`
然后使用-DOCAML_VERSION_MAJOR=$(OCAML_VERSION_MAJOR)
,-DOCAML_VERSION_MINOR=$(OCAML_VERSION_MINOR)
,...
答案 1 :(得分:3)
CAML / threads.h:
#define caml_acquire_runtime_system caml_leave_blocking_section
#define caml_release_runtime_system caml_enter_blocking_section
因此,只需将相同的行添加到您的C代码(使用#ifndef caml_acquire_runtime_system
保护),并使您的构建系统(和用户)免于依赖外部实用程序和版本号。