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

The ncurses example doesn't work for me #70

Closed
rgrinberg opened this issue Sep 1, 2013 · 2 comments
Closed

The ncurses example doesn't work for me #70

rgrinberg opened this issue Sep 1, 2013 · 2 comments

Comments

@rgrinberg
Copy link
Contributor

This is the error that I get when I run ncurses_cmd.native:

Fatal error: exception Dl.DL_error("/home/rudi/reps/ocaml-ctypes/ncurses_cmd.native: undefined symbol: initscr")

I run the most recent version of ubuntu and have installed all the ncurses packages I could find.

lib32ncurses5                                   5.9-10ubuntu4 
lib32ncurses5-dev                               5.9-10ubuntu4 
lib32ncursesw5                                  5.9-10ubuntu4 
lib32ncursesw5-dev                              5.9-10ubuntu4 
libcurses-ocaml                                 1.0.3-2       
libncurses5:amd64                               5.9-10ubuntu4 
libncurses5:i386                                5.9-10ubuntu4 
libncurses5-dev                                 5.9-10ubuntu4 
libncursesw5:amd64                              5.9-10ubuntu4 
libncursesw5:i386                               5.9-10ubuntu4 
libncursesw5-dev                                5.9-10ubuntu4 
libx32ncurses5                                  5.9-10ubuntu4 
libx32ncurses5-dev                              5.9-10ubuntu4 
libx32ncursesw5                                 5.9-10ubuntu4 
libx32ncursesw5-dev                             5.9-10ubuntu4 
ncurses-base                                    5.9-10ubuntu4 
ncurses-bin                                     5.9-10ubuntu4 
ncurses-examples                                5.9-10ubuntu4 
@yallop
Copy link
Owner

yallop commented Sep 2, 2013

The problem here is that the default behaviour of Foreign.foreign is to resolve names by looking in the current executable, and the default behaviour of the linker in recent Ubuntus is to link in only those libraries that are actually used. Since the symbols are looked up dynamically the linker can't tell that they're being used, so it doesn't link in ncurses.

Either of the following should fix the issue:

  1. Pass a flag to the linker to force it to link in the ncurses library, ignoring the fact that it can't see that ncurses is used. You can change the line that links in the ncurses library in the _oasis file to the following:
  CCLib:            -Wl,-no-as-needed -lncurses

Issue #49, when resolved, might make this no longer necessary

  1. Explicitly request resolution in the ncurses shared object at runtime. For example, you might add the following near the top of ncurses.ml:
    let foreign name typ = foreign name typ
  ~from:Dl.(dlopen ~filename:"libncurses.so.5" ~flags:[RTLD_NOW])

@yallop
Copy link
Owner

yallop commented Sep 6, 2013

Closing, but feel free to reopen if the above doesn't fix things.

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

2 participants