Search code examples
crystal-lang

execution of command failed with code: 1: `cc -o "/root/.cache/crystal/var-app-staging-new-http.cr


I am getting the following error while compiling crystal code:

[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.

This same code is getting compiled in 0.19.1 version on my mac. Any help will be greatly appreciated. Thank you.


Solution

  • Do you happen to have the libgc-dev package installed? Or did you install boehm-gc yourself? If so, it's probable that you installed the release version, which Crystal is incompatible with. You need the master version of libgc (or a carefully patched version).

    Crystal ships with a static libgc.a library, but installing another one or the shared libgc.so library will take over that embedded version.

    Please uninstall libgc-dev or if you can't, you may compile your app with --link-flags="/opt/crystal/embedded/lib/libgc.a" (assuming Crystal is installed at /opt/crystal).