0

编译水晶代码时出现以下错误:

[root@ip-172-31-53-176 staging]# cat new-http.cr
require "http/server"

srv = HTTP::Server.new(3000) do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hi world the time now is: #{Time.now}"
end
puts "Listening on 3000..."
srv.listen
[root@ip-172-31-53-176 staging]# crystal -v
Crystal 0.19.1 [798b2e2] (2016-09-09)
[root@ip-172-31-53-176 staging]# crystal build new-http.cr
_main.o: In function `~procProc(Nil)@/opt/crystal/src/fiber.cr:225':
main_module:(.text+0x4fa8): undefined reference to `GC_get_push_other_roots'
_main.o: In function `main':
main_module:(.text+0x12b89): undefined reference to `GC_set_handle_fork'
main_module:(.text+0x12edd): undefined reference to `GC_get_push_other_roots'
main_module:(.text+0x12efb): undefined reference to `GC_set_push_other_roots'
_main.o: In function `*GC::init:Nil':
main_module:(.text+0x1b437): undefined reference to `GC_set_handle_fork'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/root/.cache/crystal/var-app-staging-new-http.cr/macro-run-_opt_crystal_src_ecr_process.cr" "${@}"  -rdynamic  -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
[root@ip-172-31-53-176 staging]# cp /opt/crystal/samples/wordcount.cr .
[root@ip-172-31-53-176 staging]# crystal build wordcount.cr
_main.o: In function `__crystal_main':
main_module:(.text+0x239): undefined reference to `GC_set_push_other_roots'
_main.o: In function `~Fiber::prev_push_other_roots:init':
main_module:(.text+0x1645): undefined reference to `GC_get_push_other_roots'
G-C-.o: In function `*GC::init:Nil':
GC:(.text+0x277): undefined reference to `GC_set_handle_fork'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/var/app/staging/wordcount" "${@}"  -rdynamic  -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
[root@ip-172-31-53-176 staging]# uname -a
Linux ip-172-31-53-176 4.4.19-29.55.amzn1.x86_64 #1 SMP Mon Aug 29 23:29:40 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@ip-172-31-53-176 staging]# gcc --version
gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

相同的代码在我的 mac 上编译为 0.19.1 版本。任何帮助将不胜感激。谢谢你。

4

1 回答 1

2

你碰巧安装了 libgc-dev 包吗?还是您自己安装了 boehm-gc?如果是这样,很可能您安装了与 Crystal 不兼容的发行版。您需要 libgc 的主版本(或经过仔细修补的版本)。

Crystal 附带一个静态 libgc.a 库,但安装另一个库或共享 libgc.so 库将接管该嵌入式版本。

请卸载 libgc-dev 或者如果你不能,你可以编译你的应用程序--link-flags="/opt/crystal/embedded/lib/libgc.a"(假设 Crystal 安装在/opt/crystal)。

于 2016-09-15T08:55:46.420 回答