No implementations provided for the following modules: Str
Asked Answered
M

2

12

I have an OCaml project that uses the Str module, but when compiling, I get this error:

$ 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

This is an Oasis project with the following _oasis file:

Name: GolfCaml
Version: 0.0.0
Synopsis: GolfScript Interpreter in OCaml
Authors: Jadon Fowler <[email protected]>
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

Here is the code in question:

(* 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
Marcelenemarcelia answered 24/7, 2016 at 1:6 Comment(0)
D
8

You almost had it ;-)

Str is not in the standard library so you need to tell oasis to take it. In your _oasis file just add one thing in your Executable part :

_oasis

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

And it will work fine :

make
ocaml setup.ml -build 
Finished, 0 targets (0 cached) in 00:00:00.
Finished, 4 targets (0 cached) in 00:00:00.
Dreiser answered 24/7, 2016 at 2:17 Comment(0)
G
0

I had a similar error, but I use Ocamlbuild instead of Oasis. I added the following to my _tags file:

true: use_str

The Ocamlbuild documentation lists use_str as deprecated, replaced by ocamlfind. But I don't have the latter installed, making the use_str syntax for standard packages more convenient.

Graybeard answered 24/5, 2020 at 21:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.