【发布时间】:2014-10-05 21:22:29
【问题描述】:
刚从 ocaml 开始,并且正在努力使用各种编译器和工具。例如。 ocamlopt、ocamlc、ocamlbuild、corebuild 等等。那么,我该如何编译以下内容呢?
open Core.Std
module Regex = Re2.Regex
let ls pattern =
let pat = Regex.create_exn pattern in
let matcher = Regex.matches pat in
Sys.ls_dir "."
|> List.filter ~f:matcher
|> List.iter ~f:(fun s -> print_string s; print_newline ())
let () =
match In_channel.input_line stdin with
| None -> print_string "No Input"
| Some pat -> ls pat
在utop 我可以在#require "re2" 然后从那里开始。
如果不包含正则表达式模块,我将只使用corebuild ls.native,假设上面的代码放在ls.ml 中。
[编辑]
目前尝试过
ocamlbuild -use-ocamlfind -package core -package re2
吐出来
ocamlfind ocamldep -package core -package re2 -modules ls.ml > ls.ml.depends
ocamlfind ocamlc -c -package core -package re2 -o ls.cmo ls.ml
+ ocamlfind ocamlc -c -package core -package re2 -o ls.cmo ls.ml
ocamlfind: Error from package `threads': Missing -thread or -vmthread switch
Command exited with code 2.
所以在谷歌搜索后我被引导到this blog 我尝试了
ocamlbuild -tag thread -use-ocamlfind -package core -package re2
在失败之前会吐出 6000 多行类似于 make 的输出:
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking
Command exited with code 2.
所以我不确定接下来要尝试什么。
【问题讨论】:
-
用
ocamlbuild -use-ocamlfind -package re2 -package core ls.byte可以很好地编译,但是在编译到本机时遇到了麻烦。 -
勇敢者:gist.github.com/anonymous/971d9501385e144855d7 第一个文件是 ocamlbuild 的输出,第二个是正在编译的文件。