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

static compilation issue with openssl #6741

Closed
sam0x17 opened this issue Sep 18, 2018 · 4 comments
Closed

static compilation issue with openssl #6741

sam0x17 opened this issue Sep 18, 2018 · 4 comments

Comments

@sam0x17
Copy link
Contributor

sam0x17 commented Sep 18, 2018

A blocker for me right now is the fact that crystal programs that require "openssl" do not seem to statically compile on any of the community-managed static compilation docker images. I have set up a repo that reproduces this by running the "./build_static" bash script in the root of the project. Perhaps there are some additional dev packages that need to be included on alpine? Would highly appreciate it if someone weighs in on this. Currently this is pushing me to develop my program in rust instead, since it's openssl library compiles perfectly without any dependencies on linux + osx + windows.

repo: https://github.com/sam0x17/crystal_static_compilation
static compilation docker image: https://hub.docker.com/r/durosoft/crystal-alpine/

crystal program:

require "openssl"
puts "hey"

static compilation result:

crystal_static_compilation$ ./build_static
compiling...
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libcrypto.a(c_zlib.o): in function `zlib_stateful_expand_block':/home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:239: undefined reference to `inflate'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libcrypto.a(c_zlib.o): in function `zlib_stateful_compress_block':
/home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:210: undefined reference to `deflate'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libcrypto.a(c_zlib.o): in function `bio_zlib_free':/home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:504: undefined reference to `inflateEnd'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:509: undefined reference to `deflateEnd'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libcrypto.a(c_zlib.o): in function `zlib_stateful_finish':
/home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:187: undefined reference to `inflateEnd'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:188: undefined reference to `deflateEnd'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libcrypto.a(c_zlib.o): in function `zlib_stateful_init':/home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:157: undefined reference to `inflateInit_'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:168: undefined reference to `deflateInit_'/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libcrypto.a(c_zlib.o): in function `bio_zlib_flush':/home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:675: undefined reference to `deflate'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:680: undefined reference to `zError'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libcrypto.a(c_zlib.o): in function `bio_zlib_write':
/home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:596: undefined reference to `deflateInit_'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:630: undefined reference to `deflate'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:633: undefined reference to `zError'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libcrypto.a(c_zlib.o): in function `bio_zlib_read':
/home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:535: undefined reference to `inflateInit_'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:546: undefined reference to `inflate'
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/buildozer/aports/main/openssl1.0/src/openssl-1.0.2p/crypto/comp/c_zlib.c:549: undefined reference to `zError'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o '/app/crystal_static_compilation'  -rdynamic -static  `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'` /usr/lib/libpcre.a /usr/lib/libgc.a /usr/lib/libpthread.a /usr/lib/crystal/core/ext/libcrystal.a /usr/lib/libevent.a /usr/lib/librt.a -L/usr/lib -L/usr/local/lib`
done.

update: using this link flag fixes it by forcing libcrypto to be included before libz: --link-flags "-lcrypto -lz"

@sam0x17
Copy link
Contributor Author

sam0x17 commented Sep 18, 2018

Why, you ask, do I need static compilation? This is for a cross platform desktop app, in anticipation of upcoming windows support.

@sam0x17
Copy link
Contributor Author

sam0x17 commented Sep 18, 2018

for the lazy: this is the Dockerfile:

FROM alpine:edge
RUN apk add --update --no-cache --force-overwrite \
    openssl openssl-dev crystal shards g++ gc-dev \
    libc-dev libevent-dev libxml2-dev llvm llvm-dev \
    llvm-libs llvm-static make pcre-dev readline-dev \
    yaml-dev zlib-dev

@sam0x17
Copy link
Contributor Author

sam0x17 commented Sep 18, 2018

disregard -- I forgot we already figured this out (#6288 (comment)). For some reason this issue persists unless you add the build flags: --link-flags "-lcrypto -lz" as libcrypto needs to appear before libz. Would love it if someone could make the fix in crystal so this manual override isn't required. I'll leave the issue open until this gets fixed in crystal.

TLDR:
short term fix: add this flag: --link-flags "-lcrypto -lz"

@RX14
Copy link
Contributor

RX14 commented Sep 18, 2018

Duplicate of #6288

@RX14 RX14 marked this as a duplicate of #6288 Sep 18, 2018
@RX14 RX14 closed this as completed Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants