Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined symbol: readline #71

Closed
technomancy opened this issue Sep 1, 2013 · 4 comments
Closed

undefined symbol: readline #71

technomancy opened this issue Sep 1, 2013 · 4 comments

Comments

@technomancy
Copy link

I'm probably missing something obvious, but I couldn't figure out how to use Ctypes to define a function calling out to GNU Readline's readline function:

let read_line = foreign "readline" (string @-> returning (ptr string));;
Exception:
Dl.DL_error
 "/home/phil/.opam/4.01.0dev+trunk/lib/stublibs/dllctypes-foreign_stubs.so: undefined symbol: readline".

full toplevel transcript

This is from ctypes 0.1.1 with OCaml 4.01.0+dev18-2013-06-13 on Debian stable. I've confirmed both libffi5 and libreadline6 are installed. Any idea what's going on?

@yallop
Copy link
Owner

yallop commented Sep 2, 2013

You need to tell foreign where to find readline by passing it a handle returned by dlopen

  # #require "ctypes.foreign";;
  /home/jeremy/.opam/4.01.0dev+trunk/lib/ocaml/unix.cma: loaded
  /home/jeremy/.opam/4.01.0dev+trunk/lib/ctypes: added to search path
  /home/jeremy/.opam/4.01.0dev+trunk/lib/ctypes/ctypes.cma: loaded
  /home/jeremy/.opam/4.01.0dev+trunk/lib/ctypes/ctypes-foreign.cma: loaded
  # open Ctypes;;
  # open Foreign;;
  # let libreadline = Dl.(dlopen ~filename:"libreadline.so" ~flags:[RTLD_NOW]);;
  val libreadline : Dl.library = <abstr>
  # let read_line = foreign "readline" (string @-> returning string) ~from:libreadline;;
  val read_line : string -> string = <fun>
  # read_line "What's your name? ";;
  What's your name? Jeremy
  - : string = "Jeremy"
  #

(You also have an extra ptr in the return type.)

@technomancy
Copy link
Author

Thanks for the clarification. Is this something that should be added to the tutorial? In particular it's not clear to me why some functions (like those from ncurses) work fine without this.

@rgrinberg
Copy link
Contributor

I would also not mind a clarification. I believe my issue #70 can be fixed using the same Dl.dlopen call Jeremy used here.

@yallop
Copy link
Owner

yallop commented Sep 2, 2013

Yes, this should be covered in the tutorial. I've opened #73 as a reminder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants