Linking OCaml Code with a Shared Library

I compiled a Haskell source package that implements FFI as (.so) a dynamic library. I would like to call functions exported via FFI to OCaml. To do this, I executed a simple driver file as follows

open Quelea.Shim
open Ctypes
open PosixTypes
open Foreign

let readEffects = 
    foreign "readEffects" (ptr char @-> ptr char @-> returning ptr string)

let effects = readEffects "csasc" "saxasxas"

print_list effects

let rec print_list = function 
                [] -> ()
                | e::l -> print_int e ; print_string " " ; print_list l

Where readEffects is a function in the Quelea.Shim module of a Haskell source exported via FFI with the following signature

foreign export ccall readEffects :: CString -> CString -> IO (Ptr CString)

I tried to compile the file above (main.ml) as follows

 ocamlc -dllpath /home/parallels/.cabal/lib/Quelea-0.0.1/ghc-7.6.3 main.ml

The directory /home/parallels/.cabal/lib/Quelea-0.0.1/ghc-7.6.3contains a library file libHSQuelea-0.0.1-ghc7.6.3.so.

I get an error Error: Unbound module Quelea. How to link library with driver file?

+4
source share
1 answer

, Quelea.Shim Haskell. OCaml - Haskell Haskell.

- , :

  • , Haskell C.
  • C Haskell, . , Haskell OCaml.
  • OCaml
+1

Source: https://habr.com/ru/post/1662078/


All Articles