Basic Ocaml: How do I compile this?

fizz_ed

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

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

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.

[edit]

Have so far tried

ocamlbuild -use-ocamlfind -package core -package re2

which spit out

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

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.

fizz_ed

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 

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

Next I installed core, utop, and re2 with opam install core utop re2

And finally I ran ocamlbuild -use-ocamlfind -package re2 -package core -tag thread ls.native

which built the desired executable.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类常见问题

How do I resolve ClassNotFoundException?

来自分类Dev

How do I define the size of a CollectionView on rotate

来自分类Dev

How do I write a custom module for AngularJS?

来自分类Dev

How do I count selected checkboxes in Angular?

来自分类Dev

I do not understand how execlp() works in Linux

来自分类Dev

How do i sort my listview alphabetically?

来自分类Dev

Passing File with intent, how do i retrieve it

来自分类Dev

How do I include jquery in javafx webview?

来自分类Dev

How do I reset an Android spinner?

来自分类Dev

How do I iterate over a file?

来自分类Dev

How do I override a default keybinding in LightTable?

来自分类Dev

How do I combine lenses and functors?

来自分类Dev

How do I parse JSON in Racket?

来自分类Dev

How do I remove YUI delegated events?

来自分类Dev

How do I convert synchronous ajax to asynchronous?

来自分类Dev

How do I modularize polyfills in Angular?

来自分类Dev

How do I link boost to my program?

来自分类Dev

How do I retrieve the text of a cell comment

来自分类Dev

puppet - How do I append to path variable?

来自分类Dev

How do I call an intent in Retrofit Callback?

来自分类Dev

Is there an idiomatic way to do implicit local state in OCaml?

来自分类Dev

How to best expose ocaml library to other languages?

来自分类Dev

How do I declare a driver as global?

来自分类Dev

How do I free socket descriptors in RabbitMQ

来自分类Dev

How do I combine three observables such that

来自分类Dev

How Do I Compile/Run a java program from a Java Program (Input failure?)

来自分类Dev

How do I link to a pdf in AngularJS?

来自分类Dev

How do I parse a RestSharp response into a class?

来自分类Dev

How do I compile the latest apache2 on ubuntu using the original layout, configuration and configure options

Related 相关文章

热门标签

归档