Skip to content

Instantly share code, notes, and snippets.

@maiha
Last active October 8, 2015 08:35
Show Gist options
  • Save maiha/f99a44813b6ac9652f5a to your computer and use it in GitHub Desktop.
Save maiha/f99a44813b6ac9652f5a to your computer and use it in GitHub Desktop.
crystalでundefined referenceが出たら古い使ってないライブラリを消すべし

環境

% cat /etc/redhat-release
Scientific Linux release 6.5 (Carbon)

現象

  • 実行時にエラーが出る
/tmp % crystal eval '1'
./.crystal/eval/Event5858Base.o: In function `*Event::Base#new_event<Event::Base, Int32, LibEvent2::EventFlags, IO::FileDescriptor, &(Int32, LibEvent2::EventFlags, Pointer(Void) -> (Nil | Void))>:Event::Event':
Event::Base:(.text+0xcf): undefined reference to `event_new'
./.crystal/eval/Event5858Base.o: In function `*Event::Base#new_event<Event::Base, Int32, LibEvent2::EventFlags, Fiber, &(Int32, LibEvent2::EventFlags, Pointer(Void) -> Void)>:Event::Event':
Event::Base:(.text+0x18f): undefined reference to `event_new'
./.crystal/eval/Event5858Event.o: In function `*Event::Event#free<Event::Event>:Bool':
Event::Event:(.text+0xcc): undefined reference to `event_free'
collect2: ld はステータス 1 で終了しました
Error: execution of command failed with code: 1: `cc -o "/tmp/.crystal/crystal-run-eval.tmp" "${@}"  -rdynamic  -levent -lrt -lpcl -lpcre -lgc -lpthread -ldl`
[1]    20469 exit 1     crystal eval '1'

問題

  • libeventが正しく参照されていないぽい

確認

  • まずsystemに入ってる
/tmp % ls -l /usr/lib64/libevent*
lrwxrwxrwx. 1 root root     21 Sep  1 11:04 /usr/lib64/libevent-1.4.so.2 -> libevent-1.4.so.2.1.3*
-rwxr-xr-x. 1 root root 106656 Jun 21  2012 /usr/lib64/libevent-1.4.so.2.1.3*
-rw-r--r--. 1 root root 176258 Jun 21  2012 /usr/lib64/libevent.a
  • crystal バンドル版にも入っている
/tmp % ls -l /opt/crystal/embedded/lib/libevent*
-rw-r--r-- 1 root root 552232 Sep 19 21:21 /opt/crystal/embedded/lib/libevent.a
-rwxr-xr-x 1 root root    925 Sep 19 21:21 /opt/crystal/embedded/lib/libevent.la*
-rw-r--r-- 1 root root 328888 Sep 19 21:21 /opt/crystal/embedded/lib/libevent_core.a

crystal 版を明示する

/tmp % export LIBRARY_PATH=/opt/crystal/embedded/lib
/tmp % crystal eval '1'
./.crystal/eval/Event5858Base.o: In function `*Event::Base#new_event<Event::Base, Int32, LibEvent2::EventFlags, IO::FileDescriptor, &(Int32, LibEvent2::EventFlags, Pointer(Void) -> (Nil | Void))>:Event::Event':
Event::Base:(.text+0xcf): undefined reference to `event_new'
./.crystal/eval/Event5858Base.o: In function `*Event::Base#new_event<Event::Base, Int32, LibEvent2::EventFlags, Fiber, &(Int32, LibEvent2::EventFlags, Pointer(Void) -> Void)>:Event::Event':
Event::Base:(.text+0x18f): undefined reference to `event_new'
./.crystal/eval/Event5858Event.o: In function `*Event::Event#free<Event::Event>:Bool':
Event::Event:(.text+0xcc): undefined reference to `event_free'
collect2: ld はステータス 1 で終了しました
Error: execution of command failed with code: 1: `cc -o "/tmp/.crystal/crystal-run-eval.tmp" "${@}"  -rdynamic  -levent -lrt -lpcl -lpcre -lgc -lpthread -ldl`
[1]    20962 exit 1     crystal eval '1'
  • 変化なし (速攻諦めた)

システム版を消してみる

/tmp % yum remove libevent
  • 実行
 /tmp % crystal eval 'p 1'
1
  • 動いた ヽ(=´▽`=)ノ

知見

  • crystalバンドルと同名のライブラリでundefined referenceが出たらシステム側を消すと動く (別解切望!)
  • システム版は使ってないことを祈る
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment