ocaml
I am writing a OCaml program but want to call some C functions provided in some source code or library.
我正在编写OCaml程序,但想调用某些源代码或库中提供的某些C函数。
How to achieve this? Is there any good tutorials on this?
如何实现呢? 有什么好的教程吗?
A very good tutorial that is easy to follow and understand: How to wrap C functions to OCaml.
一个很好的教程 ,易于学习和理解: 如何将C函数包装到OCaml 。
A comprehensive reference manual: Chapter 19 Interfacing C with OCaml.
全面的参考手册: 第19章C与OCaml的接口 。
One example that calls a system call from OCaml: Calling Unix libraries from OCaml.
从OCaml 调用系统调用的一个示例:从OCaml 调用Unix库 。
If you are trying to call some Unix/Linux APIs, you may also check the Unix Module which provides the interface to the Unix system.
如果您尝试调用某些Unix / Linux API,则还可以检查提供与Unix系统接口的Unix模块 。
An example is as follows.
一个例子如下。
UseUnix.ml:
UseUnix.ml:
open Unix;;
print_string "My pid: ";;
print_int (getpid ());;
print_newline ();;
print_newline ();;
print_string "ls / -l";;
print_newline ();;
system "ls / -l";;
To run it:
运行它:
ocaml unix.cma UseUnix.ml
翻译自: https://www.systutorials.com/how-to-call-c-functions-from-ocaml-code/
ocaml