ocaml_如何从OCaml代码中调用C函数

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库

Answered by anonymous.
匿名回答。


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值