Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation failure: main.o undef refs in crystal openssl lib_ssl.cr #1

Closed
Forgen opened this issue Sep 30, 2018 · 15 comments
Closed
Labels
bug Something isn't working

Comments

@Forgen
Copy link

Forgen commented Sep 30, 2018

Description of the issue:
Compile failure related to lib_ssl.cr when building src/gpm/main.cr

Expected behavior:
make install completes

Steps to reproduce:
sudo make install

Output of crystal env:
CRYSTAL_CACHE_DIR="/home/forgen/.cache/crystal"
CRYSTAL_PATH="/usr/bin/../share/crystal/src:lib"
CRYSTAL_VERSION="0.26.1"

OS Information:
Ubuntu 18.04.1 LTS
Linux aspire-e5-575 4.15.0-34-generic #37-Ubuntu SMP Mon Aug 27 15:21:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Additional Information:
/usr/bin/shards
Fetching https://github.com/mrrooijen/commander.git
Using commander (0.3.3)
/usr/bin/crystal build --release -o bin/gpm src/gpm/main.cr
_main.o: In function __crystal_main': /usr/share/crystal/src/openssl/lib_ssl.cr:213: undefined reference to SSL_library_init'
/usr/share/crystal/src/openssl/lib_ssl.cr:213: undefined reference to SSL_load_error_strings' /usr/share/crystal/src/openssl/lib_ssl.cr:213: undefined reference to OPENSSL_add_all_algorithms_noconf'
/usr/share/crystal/src/openssl/lib_ssl.cr:213: undefined reference to ERR_load_crypto_strings' _main.o: In function default_method':
/usr/share/crystal/src/openssl/ssl/context.cr:6: undefined reference to SSLv23_method' _main.o: In function matches_subject_alternative_name':
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:34: undefined reference to sk_num' /usr/share/crystal/src/openssl/ssl/hostname_validation.cr:35: undefined reference to sk_value'
_main.o: In function ->': /usr/share/crystal/src/openssl/ssl/hostname_validation.cr:(.text+0x5e986): undefined reference to sk_pop_free'
_main.o: In function matches_subject_alternative_name': /usr/share/crystal/src/openssl/ssl/hostname_validation.cr:66: undefined reference to sk_pop_free'
_main.o: In function validate_hostname': /usr/share/crystal/src/openssl/ssl/hostname_validation.cr:(.text+0x5ea77): undefined reference to sk_pop_free'
_main.o: In function matches_subject_alternative_name': /usr/share/crystal/src/openssl/ssl/hostname_validation.cr:66: undefined reference to sk_pop_free'
_main.o: In function ->': /usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to sk_free'
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to sk_free' /usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to sk_free'
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to sk_free' /usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to sk_free'
_main.o:/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: more undefined references to sk_free' follow collect2: error: ld returned 1 exit status Error: execution of command failed with code: 1: cc "${@}" -o '/home/forgen/temp/gpm/bin/gpm' -rdynamic -lz command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto' command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto' -lpcre -lm -lgc -lpthread /usr/share/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
Makefile:7: recipe for target 'build' failed
make: *** [build] Error 1

@Forgen
Copy link
Author

Forgen commented Sep 30, 2018

Is this a crystal problem?
crystal-lang/crystal#4204

@cbrnrd
Copy link
Owner

cbrnrd commented Sep 30, 2018

It’s either a crystal problem or a commander problem. I don’t see anything relating to any gpm library files in the stacktrace. try compiling with an older version of crystal or try updating openssl

@cbrnrd
Copy link
Owner

cbrnrd commented Sep 30, 2018

the build is working on 0.26.1 with openssl v1.0.2g so it’s probably an openssl version problem

@Forgen
Copy link
Author

Forgen commented Sep 30, 2018

I checked my openssl version, it is 1.1.0g. I tried also using openssl1.0.2n using the crystal flag --link-flags "-L/usr/lib/openssl-1.0". No dice.

I downgraded crystal to 0.24.1 (which is the version where the openssl v1.1 bug fix was merged with this different result:
CRYSTAL_CACHE_DIR="/home/forgen/.cache/crystal"
CRYSTAL_PATH="/usr/bin/../share/crystal/src:lib"
CRYSTAL_VERSION="0.24.1"
forgen@aspire-e5-575:~/temp/gpm$ sudo /usr/bin/crystal build --release -o bin/gpm --error-trace src/gpm/main.cr
Error in src/gpm/main.cr:9: instantiating 'Gpm::Cli:Class#run(Array(String))'

Gpm::Cli.run(ARGV)
^~~

in src/gpm/cli.cr:9: instantiating 'Commander::Command:Class#new()'

cli = Commander::Command.new do |command|
                         ^~~

in src/gpm/cli.cr:9: instantiating 'Commander::Command:Class#new()'

cli = Commander::Command.new do |command|
                         ^~~

in src/gpm/cli.cr:42: instantiating 'Commander::Commands#add()'

  command.commands.add do |cmd|
                   ^~~

in src/gpm/cli.cr:42: instantiating 'Commander::Commands#add()'

  command.commands.add do |cmd|
                   ^~~

in src/gpm/cli.cr:48: instantiating 'Gpm::Commands::Uninstall:Class#uninstall(String)'

      Gpm::Commands::Uninstall.uninstall(args.last(1)[-1])
                               ^~~~~~~~~

in src/gpm/commands/uninstall.cr:9: instantiating 'Array(JSON::Type)#each()'

bins.as_a.each do |b|
          ^~~~

in /usr/share/crystal/src/indexable.cr:148: instantiating 'each_index()'

each_index do |i|
^~~~~~~~~~

in /usr/share/crystal/src/indexable.cr:148: instantiating 'each_index()'

each_index do |i|
^~~~~~~~~~

in src/gpm/commands/uninstall.cr:9: instantiating 'Array(JSON::Type)#each()'

bins.as_a.each do |b|
          ^~~~

in src/gpm/commands/uninstall.cr:11: undefined method 'as_s' for Array(JSON::Type) (compile-time type is (Array(JSON::Type) | Bool | Float64 | Hash(String, JSON::Type) | Int64 | String | Nil))

  rm_rf(b.as_s)
          ^~~~

================================================================================

Array(JSON::Type) trace:

src/gpm/commands/uninstall.cr:9

    bins.as_a.each do |b|

@Forgen
Copy link
Author

Forgen commented Sep 30, 2018

Info on commander version:
Fetching https://github.com/mrrooijen/commander.git
Installing commander (0.3.3)

@cbrnrd
Copy link
Owner

cbrnrd commented Sep 30, 2018

Somewhere between 0.24 and 0.26, they changed something with the JSON class. I'm going to test it on a fresh Linux VM and get back you in a few

@cbrnrd
Copy link
Owner

cbrnrd commented Sep 30, 2018

# curl -fsSL https://git.io/get-gpm | sudo bash
/usr/bin/crystal
Cloning into 'gpm'...
remote: Enumerating objects: 198, done.
remote: Total 198 (delta 0), reused 0 (delta 0), pack-reused 198
Receiving objects: 100% (198/198), 2.47 MiB | 6.24 MiB/s, done.
Resolving deltas: 100% (87/87), done.
Building gpm...
/usr/bin/shards
Fetching https://github.com/mrrooijen/commander.git
Installing commander (0.3.3)
/usr/bin/crystal build --release -o bin/gpm src/gpm/main.cr 
mkdir -p /usr/local/bin
cp ./bin/gpm /usr/local/bin
All done! Just run `sudo gpm help` to start
# crystal --version
Crystal 0.26.1 [391785249] (2018-08-27)

LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
# openssl version
OpenSSL 1.1.0h  27 Mar 2018
# uname -a
uname -a
Linux kali 4.16.0-kali2-amd64 #1 SMP Debian 4.16.12-1kali1 (2018-05-28) x86_64 GNU/Linux

I can't reproduce. Could you try using the oneliner install (and switch eveyrthing to its most recent versions)? curl -fsSL https://git.io/get-gpm | sudo bash

@Forgen
Copy link
Author

Forgen commented Oct 5, 2018

No dice. Any other ideas? I compiled and installed openssl 1.1.0h so I could exactly match yours (only 1.1.0g was available on my ubuntu apt).

$ curl -fsSL https://git.io/get-gpm | sudo bash
/usr/bin/crystal
Cloning into 'gpm'...
remote: Enumerating objects: 57, done.
remote: Counting objects: 100% (57/57), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 202 (delta 42), reused 46 (delta 35), pack-reused 145
Receiving objects: 100% (202/202), 3.03 MiB | 4.01 MiB/s, done.
Resolving deltas: 100% (86/86), done.
Building gpm...
/usr/bin/shards
Fetching https://github.com/mrrooijen/commander.git
Installing commander (0.3.3)
/usr/bin/crystal build --release -o bin/gpm src/gpm/main.cr 
_main.o: In function `__crystal_main':
/usr/share/crystal/src/openssl/lib_ssl.cr:213: undefined reference to `SSL_library_init'
/usr/share/crystal/src/openssl/lib_ssl.cr:213: undefined reference to `SSL_load_error_strings'
/usr/share/crystal/src/openssl/lib_ssl.cr:213: undefined reference to `OPENSSL_add_all_algorithms_noconf'
/usr/share/crystal/src/openssl/lib_ssl.cr:213: undefined reference to `ERR_load_crypto_strings'
_main.o: In function `default_method':
/usr/share/crystal/src/openssl/ssl/context.cr:6: undefined reference to `SSLv23_method'
_main.o: In function `matches_subject_alternative_name':
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:34: undefined reference to `sk_num'
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:35: undefined reference to `sk_value'
_main.o: In function `->':
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:(.text+0x5e9e6): undefined reference to `sk_pop_free'
_main.o: In function `matches_subject_alternative_name':
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:66: undefined reference to `sk_pop_free'
_main.o: In function `validate_hostname':
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:(.text+0x5ead7): undefined reference to `sk_pop_free'
_main.o: In function `matches_subject_alternative_name':
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:66: undefined reference to `sk_pop_free'
_main.o: In function `->':
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to `sk_free'
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to `sk_free'
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to `sk_free'
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to `sk_free'
/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: undefined reference to `sk_free'
_main.o:/usr/share/crystal/src/openssl/ssl/hostname_validation.cr:67: more undefined references to `sk_free' follow
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o '/home/forgen/opensslupgrade/gpm/bin/gpm'  -rdynamic  -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lpcre -lm -lgc -lpthread /usr/share/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
Makefile:7: recipe for target 'build' failed
make: *** [build] Error 1

$ crystal --version
Crystal 0.26.1 [391785249] (2018-08-27)

LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu

$ openssl version
OpenSSL 1.1.0h  27 Mar 2018

@cbrnrd
Copy link
Owner

cbrnrd commented Oct 5, 2018

This is a really weird issue. From what you’ve told me our environments are exactly the same, but you’re getting an error. I’ve compiled on mac, linux, and WSL and no failures. Have you been installing the openssl package or the libssl-dev package? You could be missing some openssl headers needed for compilation.

@cbrnrd cbrnrd added the bug Something isn't working label Oct 7, 2018
@Forgen
Copy link
Author

Forgen commented Oct 8, 2018

I have been installing the openssl package. I fubar'd my ubuntu so I reinstalled Ubuntu 18, then installed the matching set of libssl, libssl-dev, and openssl to your version:
libssl1.1_1.1.0h-4_amd64.deb
libssl-dev_1.1.0h-4_amd64.deb
openssl_1.1.0h-1_amd64.deb

Identical result.

For completeness, here is the sequence of things that were installed from the fresh ubuntu install (in addition to the packages above):

``~$ curl -fsSL https://git.io/get-gpm | sudo bash
The crystal compiler is not installed. Installing...
Executing: /tmp/apt-key-gpghome.DwqDmvlI4d/gpg.1.sh --keyserver keys.gnupg.net --recv-keys 09617FD37CC06B54
gpg: key 09617FD37CC06B54: public key "Crystal Distribution Signing [email protected]" imported
gpg: Total number processed: 1
gpg: imported: 1
Hit:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease
Get:3 https://dist.crystal-lang.org/apt crystal InRelease [2,478 B]
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Get:6 https://dist.crystal-lang.org/apt crystal/main amd64 Packages [440 B]
Get:7 https://dist.crystal-lang.org/apt crystal/main i386 Packages [447 B]
Fetched 3,365 B in 2s (2,130 B/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
cpp cpp-7 dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base git git-man
libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
libasan4 libatomic1 libc-dev-bin libc6-dev libcilkrts5 liberror-perl
libevent-core-2.1-6 libevent-dev libevent-extra-2.1-6 libevent-openssl-2.1-6
libevent-pthreads-2.1-6 libfakeroot libgcc-7-dev libitm1 liblsan0 libmpx2
libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libquadmath0
libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev make manpages-dev
Suggested packages:
cpp-doc gcc-7-locales libxml2-dev libgmp-dev libyaml-dev libreadline-dev
debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg
gcc-multilib autoconf automake libtool flex bison gcc-doc gcc-7-multilib
libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan4-dbg
liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg
libquadmath0-dbg git-daemon-run | git-daemon-sysvinit git-doc git-el
git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn glibc-doc
libstdc++-7-doc make-doc
The following NEW packages will be installed:
build-essential crystal dpkg-dev fakeroot g++ g++-7 gcc gcc-7 git git-man
libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
libasan4 libatomic1 libc-dev-bin libc6-dev libcilkrts5 liberror-perl
libevent-core-2.1-6 libevent-dev libevent-extra-2.1-6 libevent-openssl-2.1-6
libevent-pthreads-2.1-6 libfakeroot libgcc-7-dev libitm1 liblsan0 libmpx2
libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libquadmath0
libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev make manpages-dev
The following packages will be upgraded:
cpp cpp-7 gcc-7-base
3 upgraded, 40 newly installed, 0 to remove and 185 not upgraded.

~$ curl -fsSL https://git.io/get-gpm | sudo bash
/usr/bin/crystal
Cloning into 'gpm'...
remote: Enumerating objects: 57, done.
remote: Counting objects: 100% (57/57), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 202 (delta 42), reused 46 (delta 35), pack-reused 145
Receiving objects: 100% (202/202), 3.03 MiB | 1.34 MiB/s, done.
Resolving deltas: 100% (86/86), done.
Building gpm...
/usr/bin/shards
Fetching https://github.com/mrrooijen/commander.git
Installing commander (0.3.3)
/usr/bin/crystal build --release -o bin/gpm src/gpm/main.cr
/usr/bin/ld: cannot find -lz (this usually means you need to install the development package for libz)
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: cc "${@}" -o '/home/forgen/gpm/bin/gpm' -rdynamic -lz command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto' command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto' -lpcre -lm -lgc -lpthread /usr/share/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib
Makefile:7: recipe for target 'build' failed
make: *** [build] Error 1

:~$ sudo apt install zlib1g-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
zlib1g-dev
0 upgraded, 1 newly installed, 0 to remove and 185 not upgraded.

@cbrnrd
Copy link
Owner

cbrnrd commented Oct 8, 2018

That seems like a different error unrelated to OpenSSL. How did it go after installing libz?

Reason:

/usr/bin/ld: cannot find -lz (this usually means you need to install the development package for libz)
collect2: error: ld returned 1 exit status

@Forgen
Copy link
Author

Forgen commented Oct 9, 2018

The final result was the same as the earlier post, starting with
_"/usr/bin/crystal build --release -o bin/gpm src/gpm/main.cr
main.o: In function __crystal_main': /usr/share/crystal/src/openssl/lib_ssl.cr:213: undefined reference to SSL_library_init'"
I just didn't re-include that part, sorry.

@cbrnrd
Copy link
Owner

cbrnrd commented Oct 9, 2018

All good. Have you looked at crystal-lang/crystal#4680? It seems that issue mentions your problem.

@Forgen
Copy link
Author

Forgen commented Oct 13, 2018

Eureka! That's the key. pkgconf is required.

$ sudo apt install pkgconf
(...pkgconf_0.9.12-6_amd64.deb..)

$ curl -fsSL https://git.io/get-gpm | sudo bash
/usr/bin/crystal
Cloning into 'gpm'... 
Building gpm...
/usr/bin/shards
Fetching https://github.com/mrrooijen/commander.git
Installing commander (0.3.3)
/usr/bin/crystal build --release -o bin/gpm src/gpm/main.cr 
mkdir -p /usr/local/bin
cp ./bin/gpm /usr/local/bin
All done! Just run `sudo gpm help` to start

@Forgen Forgen closed this as completed Oct 13, 2018
@cbrnrd
Copy link
Owner

cbrnrd commented Oct 14, 2018

Wow, all that for just pkgconf. You may want to report that bug to crystal and tell them it's a dependency and should be installed with the crystal installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants