The Crystal Programming Language Forum

Static build when using readline lib

I am trying to build a static linked binary of my some tool I wrote that utilizes readline. I am using alpine:edge docker image - here is the dockerfile content (basically it is durosoft/crystal-alpine):

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-static make pcre-dev readline-dev \
yaml-dev zlib-dev zlib ncurses-dev

But it fails complaining about cannot find -lncursesw (this usually means you need to install the development package for libncursesw):

# shards build --static
Dependencies are satisfied
Building: ootb
Error target ootb failed to compile:
/usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lncursesw (this usually means you need to install the development package for libncursesw)
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o '/work/ootb/bin/ootb'  -rdynamic -static  /usr/lib/libreadline.a -lncursesw -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'` /usr/lib/libpcre.a /usr/lib/libm.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`

Can somebody please help? What is “cursesw” lib? I tried to “apk add” it but it fails anyway:

# apk add ncursesw
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  ncursesw (missing):
    required by: world[ncursesw]

Hello, welcome ;)

You need to install ncurses-libs, ref: https://pkgs.alpinelinux.org/package/v3.4/main/x86/ncurses-libs
You can see in the package content that the libncursesw library is present.

Thank you for quick reply. I tried to add ncurses-libs but it did not go:

# apk add ncurses-libs
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/edge/main: Permission denied
...
WARNING: Ignoring APKINDEX.b53994b4.tar.gz: No such file or directory
OK: 514 MiB in 74 packages

Am I missing some other steps? Is it a problem with repositories? Should I add another repo to pull this lib from?

Actually, my bad - proxy was blocking connections to repo. I was able to add “ncurses-libs” to the docker image but it did not solve the original problem - still getting:

/usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lncursesw (this usually means you need to install the development package for libncursesw)

Figured it out finally. What is actually needed is
apk add ncurses-static

This solves it.

2 Likes