简体   繁体   English

错误:Ocaml中的未绑定模块Unix

[英]Error: Unbound module Unix in Ocaml

I started programming with Ocaml 2 days ago, I have been through the basic stuff and I wanted to start trying to create Processes. 我在2天前开始使用Ocaml编程,我已经完成了基本的工作,我想开始尝试创建进程。

In the book I am using the tell me to use the Unix module, so far so good... But I get this error when I try to run a simple code that prints the time: 在我使用的书中告诉我使用Unix模块,到目前为止一切都很好......但是当我尝试运行打印时间的简单代码时,我收到此错误:

open Unix ;;
let t = Unix.localtime (Unix.time ());;


Printf.printf "Today is day %d of the current year.\n" t.tm_yday ;;

And I get this error: 我收到这个错误:

Error: Unbound module Unix

I searched for an answer to this and I found I should compile my code with "unix.cma" linked, after this I was able to compile, but the code does nothing. 我搜索了一个答案,我发现我应该用“unix.cma”链接编译我的代码,之后我能够编译,但代码什么也没做。

I know it might be a very noobish question, but I can't keep going on without this. 我知道这可能是一个非常无聊的问题,但如果没有这个问题我就无法继续下去。 Is a library missing? 图书馆遗失了吗?

If I run in top level it says the #load is and unbound value also ! 如果我在顶级运行它会说#load is and unbound value also

Thank you for your time! 感谢您的时间!

Edit: 编辑:

I recompile it with the "unix.cma" linked, and obtained the same error: Error: Unbound module Unix 我用“unix.cma”链接重新编译它,并获得了同样的错误: Error: Unbound module Unix

Might be a library issue? 可能是图书馆问题?

I did ocamlc -where and it all seems fine, meaning all the usual libraries are in the PATH, including unix.cma 我做了ocamlc -where,一切看起来都很好,这意味着所有常用的库都在PATH中,包括unix.cma

Solved 解决了

It was all due to a bad installation of Ocaml. 这完全是由于Ocaml安装不当造成的。 Thank you Jeffrey Scofield 谢谢杰弗里斯科菲尔德

It works here for me. 它适用于我。 Here is a toplevel session (Mac OS X 10.8.2): 这是一个顶级会话(Mac OS X 10.8.2):

$ ocaml
        OCaml version 4.00.0

# #load "unix.cma";;
# open Unix;;
# let t = Unix.localtime (Unix.time ());;
val t : Unix.tm =
  {tm_sec = 39; tm_min = 27; tm_hour = 16; tm_mday = 3; tm_mon = 11;
   tm_year = 112; tm_wday = 1; tm_yday = 337; tm_isdst = false}
# Printf.printf "Today is day %d of the current year.\n" t.tm_yday;;
Today is day 337 of the current year.
- : unit = ()
# 

Here is a session with the compiler: 这是与编译器的会话:

$ cat doy.ml
open Unix

let t = Unix.localtime (Unix.time ());;

Printf.printf "Today is day %d of the current year.\n" t.tm_yday
$ ocamlc -o doy unix.cma doy.ml
$ doy
Today is day 337 of the current year.

If these don't work for you, my only theory is that your OCaml installation isn't complete. 如果这些不适合您,我唯一的理论是您的OCaml安装不完整。 What type of system are you using? 你使用什么类型的系统?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM