Closed Val closed 7 years ago
This is more a Linux distribution libyajl override issue, see https://github.com/crystal-lang/crystal/issues/1269#issuecomment-306478314 & https://github.com/crystal-lang/crystal/issues/1269#issuecomment-306490121 .
@Val what happens if you specify -lyajl
? Searching for information about the error, then reading the error message made me realize the DSO missing from command line
part in the error message, related to libyajl
. It looks like it needs symbols from libyajl
but it won't because it's not supposed to, since -lyajl
isn't specified in the cc
command.
src/try_mongo.cr
with -lyajl
:
require "mongo"
@[Link(ldflags: "-lyajl")]
client = Mongo::Client.new "mongodb://localhost"
db = client["test"]
collection = db["mongo_try"]
puts collection.count
Build attempt:
try_mongo> crystal deps build
Dependencies are satisfied
Building: try_mongo
Error target try_mongo failed to compile:
/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 "try_mongo/bin/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`
@ysbaddaden : -lyajl
should have been added in the cc
command line ?
@ysbaddaden if you want to reproduce a Debian environment with a vagrant up stretch64
: https://github.com/Val/crystal/compare/master...Val:add_debian_distribs_to_vagrantfile plus a sudo apt-get -y install libmongoc-1.0 libbson-1.0
@ysbaddaden sorry if I bug you with this but you didn't respond to https://github.com/datanoise/mongo.cr/issues/22#issuecomment-306793932 .
Do you think -lyajl
missing from the cc
command line is normal when @[Link(ldflags: "-lyajl")]
is added ?
It seems to be a compiler bug, see https://github.com/crystal-lang/crystal/issues/4825 so closing.
Environment: a Debian stretch up to date, with
libmongoc-dev
packageCode: an attempt to connect to a local Mongo database.
Adding mongo.cr
Add basic code to try db connect
Attempt to build...