crystal-lang / crystal_lib

Automatic binding generator for native libraries in Crystal
138 stars 30 forks source link

libLLVM-3.6.so.1: error adding symbols: DSO missing from command line #25

Open zcassini opened 8 years ago

zcassini commented 8 years ago

I'm getting this error trying to generate the examples. I have libllvm3.6v5 and libllvm3.6-dbg packages installed. I also have llvm 3.8 installed. I'm not sure how this linking works.

> crystal src/main.cr -- examples/lib_git2.cr
/usr/bin/ld: /opt/crystal/embedded/lib/../lib/libgc.a(os_dep.o): undefined reference to symbol '_end'
//usr/lib/x86_64-linux-gnu/libLLVM-3.6.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/home/zac/.cache/crystal/crystal-run-main.tmp" "${@}"  -rdynamic  -L/usr/lib -L/usr/local/lib `llvm-config-3.6 --ldflags 2>/dev/null || llvm-config-3.5 --ldflags 2>/dev/null || llvm-config --ldflags 2>/dev/null` -lclang -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl`

Some version info:

> llvm-config-3.6 --version                  
3.6.2
> llvm-config --version                      
3.8.0
> crystal -v                                 
Crystal 0.18.0 [25b7925] (2016-06-14)
> cat /proc/version
Linux version 4.4.0-24-generic (buildd@lgw01-12) (gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2.1) ) #43-Ubuntu SMP Wed Jun 8 19:27:37 UTC 2016
> cat /etc/issue
Ubuntu 16.04 LTS \n \l
asterite commented 8 years ago

Sorry, I never tried this on Ubuntu, I'm on OSX so I don't know why it doesn't work.

Seems to be related to https://github.com/crystal-lang/crystal/issues/1269 and https://github.com/will/crystal-pg/issues/14

AllanCochrane commented 7 years ago

This is still an issue with the latest version of Crystal, any chance someone could take a look?

$ crystal -v
Crystal 0.22.0 [3c71228] (2017-04-20) LLVM 3.5.0

$ cat /etc/issue
Ubuntu 16.04.2 LTS

$ cat mosquitto.cr
@[Link("mosquitto")]
lib LibMosquitto
# In C: double cos(double x)
#fun cos(value : Float64) : Float64

fun init = mosquitto_lib_init
fun version = mosquitto_lib_version(major : Int32*, minor : Int32*, revision : Int32*) : Int32

end

LibMosquitto.init
crystal mosquitto.cr

The output is:

/usr/bin/ld: /opt/crystal/embedded/lib/../lib/libgc.a(os_dep.o): undefined reference to symbol '_end'
//usr/lib/x86_64-linux-gnu/libcares.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/home/allan/.cache/crystal/crystal-run-mosquitto.tmp" "${@}"  -rdynamic  -lmosquitto -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
Val commented 7 years ago

Agreed, it's still an issue. Here is another example when using mongo.cr

Environment: a Debian stable (jessie) up to date.

> crystal --version
Crystal 0.22.0 [3c71228] (2017-04-20) LLVM 3.5.0
> llvm-config-3.5 --version
3.5.0
> cat /etc/{issue,debian_version}
Debian GNU/Linux 8 \n \l

8.8

Code: an attempt to connect to a local Mongo database.

> crystal init app try_mongo
      create  try_mongo/.gitignore
      create  try_mongo/LICENSE
      create  try_mongo/README.md
      create  try_mongo/.travis.yml
      create  try_mongo/shard.yml
      create  try_mongo/src/try_mongo.cr
      create  try_mongo/src/try_mongo/version.cr
      create  try_mongo/spec/spec_helper.cr
      create  try_mongo/spec/try_mongo_spec.cr
Initialized empty Git repository in /path/to/try_mongo/.git/

Adding mongo.cr

> cd try_mongo
try_mongo> cat >> shard.yml 
dependencies:
  mongo:
    github: datanoise/mongo.cr
    branch: master
^D
try_mongo> shards install
Updating https://github.com/datanoise/mongo.cr.git
Installing mongo (master)

Add basic code to try db connect

try_mongo> cat > src/try_mongo.cr 
require "mongo"

client = Mongo::Client.new "mongodb://localhost"
db = client["test"]
collection = db["mongo_try"]

puts collection.count
^D

Attempt to build...

try_mongo> crystal build src/try_mongo.cr 
/usr/bin/ld: /opt/crystal/embedded/lib/../lib/libgc.a(os_dep.o): undefined reference to symbol '_end'
//usr/lib/x86_64-linux-gnu/libyajl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/path/to/try_mongo/try_mongo" "${@}"  -rdynamic  -lmongoc-1.0 -lbson-1.0 -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
akzhan commented 7 years ago

Looks like author doesn't provide ldflags to the library. Just for example:

@[Link(ldflags: "#{__DIR__}/ext/libcrystal.a")]
Val commented 7 years ago

@akzhan How do you use this trick on the previous example ?

akzhan commented 7 years ago

@[Link(ldflags: "location of correct library.")] in your crystal shim code (where is link attribute).

Val commented 7 years ago

@akzhan : seems ldflags are already provided.

> grep -r Link .
./lib/mongo/src/mongo/lib_mongo.cr:@[Link("mongoc-1.0")]
./lib/mongo/src/bson/lib_bson.cr:@[Link("bson-1.0")]
Val commented 7 years ago

Still unable to try mongo.cr, even on Debian stretch (the next stable release), cf. https://github.com/datanoise/mongo.cr/issues/22

Val commented 7 years ago

Found a bug in @[Link(ldflags: "...")], see https://github.com/crystal-lang/crystal/issues/4825

funny-falcon commented 7 years ago

caught again in Ubuntu 17.10:

$ crystal -v
Crystal 0.23.1 [e2a1389] (2017-07-13) LLVM 3.8.1
$ git log -n 1
commit 007899ac1eebe45043c8350ade85bc62e1783517 (HEAD -> master, origin/master, origin/HEAD)
Author: Julien Portalier <julien@portalier.com>
Date:   Thu Oct 12 14:30:34 2017 +0200

    Fix: always use monotonic clock to measure time

    Mostly fixes spec, benchmark and some compiler timings.

$ LANG=C make clean crystal
Using /usr/bin/llvm-config-4.0 [version=4.0.1]
rm -rf .build
rm -rf ./doc
rm -rf src/llvm/ext/llvm_ext.o
rm -rf src/ext/sigfault.o src/ext/libcrystal.a
g++ -c  -o src/llvm/ext/llvm_ext.o src/llvm/ext/llvm_ext.cc `/usr/bin/llvm-config-4.0 --cxxflags`
cc -fPIC    -c -o src/ext/sigfault.o src/ext/sigfault.c
ar -rcs src/ext/libcrystal.a src/ext/sigfault.o
CRYSTAL_CONFIG_PATH=`pwd`/src ./bin/crystal build  -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
/usr/bin/ld: /opt/crystal/embedded/lib/../lib/libgc.a(os_dep.o): undefined reference to symbol '_end'
//usr/lib/x86_64-linux-gnu/libffi.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o '/home/yura/Projects/crystal/.build/crystal'  -rdynamic  /home/yura/Projects/crystal/src/llvm/ext/llvm_ext.o `/usr/bin/llvm-config-4.0 --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lpcre -lm -lgc -lpthread /home/yura/Projects/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
Makefile:117: recipe for target '.build/crystal' failed
make: *** [.build/crystal] Error 1
Dan-Do commented 3 years ago

I had the same issue yesterday with other DSO. It seems I have to install the dev library on Ubuntu. My bad I cannot recall what exactly been done :(