基本Ocaml:我该如何编译? [英] Basic Ocaml: How do I compile this?

查看:420
本文介绍了基本Ocaml:我该如何编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅从ocaml开始,就在各种编译器和工具方面苦苦挣扎.例如. ocamloptocamlcocamlbuildcorebuild等.那么,我该如何编译以下内容?

Just beginning with ocaml and am struggling with the various compilers and tooling. E.g. ocamlopt, ocamlc, ocamlbuild, corebuild and so on. So, how do I compile the following?

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"然后从那里去.

In utop I can just #require "re2" and go from there.

在不包含正则表达式模块的情况下,我将仅使用corebuild ls.native,假设上面的代码已放置在ls.ml中.

Without the inclusion of the regular expressions module I would just use corebuild ls.native, assuming that the above code is placed into 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.

因此,经过一番谷歌搜索后,我被带到了此博客我尝试过

So after some googling I was led to this blog I tried

ocamlbuild -tag thread -use-ocamlfind -package core -package re2

会在失败之前吐出6000行以上的make输出:

which spits out over 6000 lines of what looks like make output before failing with:

collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking
Command exited with code 2.

所以我不确定下一步该怎么做.

so I'm not sure what to try next.

推荐答案

我正在64位计算机上使用Ubuntu 14.04.我放弃了ocaml的apt-get版本:

I am using Ubuntu 14.04 on a 64bit machine. I ditched the apt-get versions of ocaml:

sudo apt-get remove --purge ocaml ocaml-base-nox ocaml-compiler-libs \ 
                            ocaml-interp ocaml-native-compilers \ 
                            ocaml-nox campl4 ocaml-base ocaml-docs opam 

然后我按照此处的说明从源代码安装了opam.

Then I installed opam from source according to the instructions here.

接下来,我用opam install core utop re2

最后我跑了ocamlbuild -use-ocamlfind -package re2 -package core -tag thread ls.native

构建了所需的可执行文件.

which built the desired executable.

这篇关于基本Ocaml:我该如何编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆