没有为以下模块提供实现:Str

时间:2016-07-24 01:06:51

标签: ocaml oasis

我有一个使用Str模块的OCaml项目,但在编译时,我收到此错误:

$ make                            
ocaml setup.ml -build                                                    
Finished, 0 targets (0 cached) in 00:00:00.
+ /home/phase/.opam/system/bin/ocamlfind ocamlopt -g -linkpkg src/objects.cmx src/golf.cmx -o src/golf.native
File "_none_", line 1:                                                   
Error: No implementations provided for the following modules:            
         Str referenced from src/golf.cmx                                
Command exited with code 2.
Compilation unsuccessful after building 7 targets (6 cached) in 00:00:00.
E: Failure("Command ''/usr/bin/ocamlbuild' src/golf.native -tag debug' terminated with error code 10")
Makefile:7: recipe for target 'build' failed
make: *** [build] Error 1

这是一个带有以下_oasis文件的Oasis项目:

Name: GolfCaml
Version: 0.0.0
Synopsis: GolfScript Interpreter in OCaml
Authors: Jadon Fowler <jadonflower@gmail.com>
License: https://www.mozilla.org/en-US/MPL/2.0/

Description: GolfCaml is an interpreter for GolfScript in OCaml.
Homepage: http://jadonfowler.xyz/

OASISFormat: 0.4
BuildTools: ocamlbuild
Plugins: META (0.4), DevFiles (0.4)

Executable "golfcaml"
  Path: src
  MainIs: golf.ml
  CompiledObject: best

以下是相关代码:

(* Token Regex from http://www.golfscript.com/golfscript/syntax.html *)
let token_regex = Str.regexp "[a-zA-Z_][a-zA-Z0-9_]*|'(?:\\.|[^'])*'?|\"(?:\\.|[^\"])*\"?|-?[0-9]+|#[^\n\r]*|."

(* Iterate of a line and interpret each char *)
let interpret_line line =
  let tokens = Str.split token_regex line in
  List.iter (fun (x) -> printf "%s\n" x) tokens

2 个答案:

答案 0 :(得分:6)

你几乎拥有它; - )

Str不在标准库中,因此您需要告诉oasis接受它。在_oasis文件中,只需在Executable部分添加一项内容:

<强> _oasis

Executable "golfcaml"
  Path: src
  MainIs: golf.ml
  CompiledObject: best
  BuildDepends:
    str

它会正常工作:

make
ocaml setup.ml -build 
Finished, 0 targets (0 cached) in 00:00:00.
Finished, 4 targets (0 cached) in 00:00:00.

答案 1 :(得分:0)

我有一个类似的错误,但是我使用Ocamlbuild而不是Oasis。我将以下内容添加到我的_tags文件中:

true: use_str

Ocamlbuild documentationuse_str列为已弃用,由ocamlfind代替。但是我没有安装后者,这使得标准软件包的use_str语法更加方便。