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

linker command failed with some Readline methods #4067

Closed
jwoertink opened this issue Feb 23, 2017 · 15 comments
Closed

linker command failed with some Readline methods #4067

jwoertink opened this issue Feb 23, 2017 · 15 comments

Comments

@jwoertink
Copy link
Contributor

When using a few of the Readline methods, I get the following error:

Undefined symbols for architecture x86_64:
  "_rl_unbind_key", referenced from:
      _*Readline@Readline::unbind_key<Char>:Nil in R-eadline.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc -o "/Users/jeremywoertink/.cache/crystal/crystal-run-sample.tmp" "${@}"  -rdynamic  -lreadline -lpcre -lgc -lpthread /usr/local/Cellar/crystal-lang/0.21.0/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`

Here's the code:

require "readline"

Readline.unbind_key('t')

loop do
  Readline.readline("Enter code: ", true)
end

Running Crystal 0.21.0 (2017-02-21) on macOS 10.12.3

@asterite
Copy link
Member

asterite commented Mar 4, 2017

I think this is an issue with OSX and readline, not Crystal. Crystal simply links against whatever readline you have installed in your system. An update to readline on your machine should fix this (though I don't know how to do that right now).

@jwoertink
Copy link
Contributor Author

I have the latest readline 7.0 installed. I'm not familiar with how linking C packages work, but if I can get a similar example running in straight readline outside of crystal, would that help?

I think @Sija had tried this on linux as well and got the same error. Does this example work on your machine? Maybe we can see what the difference is to see what linked package is missing?

@Sija
Copy link
Contributor

Sija commented Mar 4, 2017

@jwoertink Truth to be told I've been trying that on my macOS (10.11.6) machine :)

I have readline: stable 7.0.3 (bottled) [keg-only] installed via homebrew but it's not linked, so the error was coming from my system libreadline I think.

@jwoertink
Copy link
Contributor Author

Ah. Ok, so same as me then. How do we link it to see if that's the issue?

@Sija
Copy link
Contributor

Sija commented Mar 4, 2017

@jwoertink brew link readline --force

@jwoertink
Copy link
Contributor Author

Still same error:

[14:25PM] debugger$ brew link readline --force
Linking /usr/local/Cellar/readline/7.0... 17 symlinks created
[14:25PM] debugger$ crystal sample.cr 
Undefined symbols for architecture x86_64:
  "_rl_unbind_key", referenced from:
      _*Readline@Readline::unbind_key<Char>:Nil in R-eadline.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc -o "/Users/jeremywoertink/.cache/crystal/crystal-run-sample.tmp" "${@}"  -rdynamic  -lreadline -lpcre -lgc -lpthread /usr/local/Cellar/crystal-lang/0.21.0/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`

@Sija
Copy link
Contributor

Sija commented Mar 4, 2017

@jwoertink did you clear your ~/.cache/crystal before? (just to be sure...)

@jwoertink
Copy link
Contributor Author

yeah, I had cleared that out. In fact, trying to fix another issue I had, I had to completely uninstall crystal and clear out a bunch of things, so I was able to start fresh. Are you saying that you were able to get it to work on macOS, @Sija?

@Sija
Copy link
Contributor

Sija commented Mar 5, 2017

@jwoertink nope, but didn't tried very hard (mostly thinking of changing versions and relinking the lib through homebrew).

@russ
Copy link

russ commented Mar 6, 2017

Running the same code on an Ubuntu install does work. So it seems there is a version mismatch or something else wrong with libreadline on OSX.

Ubuntu Version:

root@24b0024d307b:/opt/crystal-head# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 14.04.5 LTS
Release:	14.04
Codename:	trusty

Installed versions of libreadline

libreadline6/trusty,now 6.3-4ubuntu2 amd64 [installed]
libreadline6-dev/trusty,now 6.3-4ubuntu2 amd64 [installed]

@jwoertink
Copy link
Contributor Author

Not sure if this helps shed some light or not, but I tried using --link-flag (probably incorrectly:

[14:57PM] debugger$ crystal build --release sample.cr --link-flags /usr/local/Cellar/readline/7.0/lib/libreadline.a
Undefined symbols for architecture x86_64:
  "_BC", referenced from:
      __rl_init_terminal_io in libreadline.a(terminal.o)
  "_PC", referenced from:
      __rl_init_terminal_io in libreadline.a(terminal.o)
  "_UP", referenced from:
      __rl_init_terminal_io in libreadline.a(terminal.o)
  "_tgetent", referenced from:
      __rl_init_terminal_io in libreadline.a(terminal.o)
  "_tgetflag", referenced from:
      __rl_init_terminal_io in libreadline.a(terminal.o)
  "_tgetnum", referenced from:
      __rl_get_screen_size in libreadline.a(terminal.o)
  "_tgetstr", referenced from:
      __rl_init_terminal_io in libreadline.a(terminal.o)
  "_tgoto", referenced from:
      _update_line in libreadline.a(display.o)
  "_tputs", referenced from:
      __rl_backspace in libreadline.a(terminal.o)
      _rl_ding in libreadline.a(terminal.o)
      __rl_enable_meta_key in libreadline.a(terminal.o)
      __rl_disable_meta_key in libreadline.a(terminal.o)
      __rl_control_keypad in libreadline.a(terminal.o)
      __rl_set_cursor in libreadline.a(terminal.o)
      _rl_redisplay in libreadline.a(display.o)
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc -o "/Users/jeremywoertink/Development/crystal/debugger/sample" "${@}" /usr/local/Cellar/readline/7.0/lib/libreadline.a -rdynamic  -lreadline -lpcre -lgc -lpthread /usr/local/Cellar/crystal-lang/0.21.1/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`

but it gave a lot more output

@Sija
Copy link
Contributor

Sija commented Mar 13, 2017

@jwoertink Did you try older version of libreadline (6.x)?

@jwoertink
Copy link
Contributor Author

@Sija No. I only have 7.0 on my machine, and I can't find a 6.x version through homebrew.

@jwoertink
Copy link
Contributor Author

ok, I found a 6.3.8 version and was able to install, but I get the same error.

@RX14
Copy link
Contributor

RX14 commented Mar 22, 2020

Not relevant any more, see #8364

@RX14 RX14 closed this as completed Mar 22, 2020
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

5 participants