Question about FFI

When I am reading the chapter about FFI,I get two questions.

  1. When importing ctypes-foreign module , Which sentence should I use?
require "ctypes-foreign" ;;

or

require "ctypes.foreign" ;;

? The later is work fine for me.
2. When I execute

let initscr =
  foreign "initscr" (void @-> returning window);;

I get an Exception ,

Exception: Dl.DL_error(“dlsym(RTLD_DEFAULT, initscr): symbol not found”).
Raised at Dl._report_dl_error in file “src/ctypes-foreign-base/dl.ml”, line 42, characters 20-44
Called from Ctypes_foreign_basis.Make.foreign in file “src/ctypes-foreign-base/ctypes_foreign_basis.ml”, line 47, characters 19-47
Re-raised at Ctypes_foreign_basis.Make.foreign in file “src/ctypes-foreign-base/ctypes_foreign_basis.ml”, line 49, characters 50-59
Called from unknown location
Called from Toploop.load_lambda in file “toplevel/toploop.ml”, line 212, characters 17-27

I have no idea about this .

the current name is ctypes.foreign. ctypes-foreign is the intended new name in a version that is not yet released.

If ncurses isn’t linked in by default, you have to load it manually:

let curses = Dl.(dlopen ~filename:"/path/to/libncursesw.so" ~flags:[RTLD_NOW])
let initscr = foreign ~from:curses "initscr" (void @-> returning window)
1 Like