Building static apps using libxml with official docker image

Hey,

I am trying to build an app using the official docker image.

In order to reproduce you need an app to use libxml like aws

dependencies:
  aws:
    github: sdogruyol/aws

src/test.cr can be like this

require "aws"

# TODO: Write documentation for `Test`
module Test
  VERSION = "0.1.0"

  # TODO: Put your code here
end

Trying to compile this with the official docker image ends up as

docker run --rm -it -v $PWD:/app -w /app crystallang/crystal:latest crystal build src/test.cr -o bin/bootstrap --release --no-debug --static
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(nanohttp.o): In function `xmlNanoHTTPConnectHost':
(.text+0x924): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(nanohttp.o): In function `xmlNanoHTTPConnectHost':
(.text+0x9f4): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libevent.a(evutil.o): In function `evutil_getaddrinfo_common':
(.text+0x1749): warning: Using 'getprotobynumber' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xpath.o): In function `xmlXPathCastNumberToString':
(.text+0xa3d7): undefined reference to `log10'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xpath.o): In function `xmlXPathStringEvalNumber':
(.text+0xd6ff): undefined reference to `pow'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xpath.o): In function `xmlXPathCeilingFunction':
(.text+0xdeee): undefined reference to `fmod'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xpath.o): In function `xmlXPathFloorFunction':
(.text+0xdfee): undefined reference to `fmod'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xpath.o): In function `xmlXPathRoundFunction':
(.text+0xe123): undefined reference to `fmod'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xpath.o): In function `xmlXPathModValues':
(.text+0xec3c): undefined reference to `fmod'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xpath.o): In function `xmlXPathCompPathExpr':
(.text+0x1582d): undefined reference to `pow'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `openIcuConverter':
(.text+0x104b): undefined reference to `ucnv_open_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `openIcuConverter':
(.text+0x1077): undefined reference to `UCNV_FROM_U_CALLBACK_STOP_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `openIcuConverter':
(.text+0x107c): undefined reference to `ucnv_setFromUCallBack_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `openIcuConverter':
(.text+0x109b): undefined reference to `ucnv_open_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `openIcuConverter':
(.text+0x10b7): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `openIcuConverter':
(.text+0x10eb): undefined reference to `UCNV_TO_U_CALLBACK_STOP_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `openIcuConverter':
(.text+0x10f0): undefined reference to `ucnv_setToUCallBack_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `closeIcuConverter':
(.text+0x111d): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `closeIcuConverter':
(.text+0x1126): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlFindCharEncodingHandler':
(.text+0x2793): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlFindCharEncodingHandler':
(.text+0x279d): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlFindCharEncodingHandler':
(.text+0x27b3): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o):(.text+0x27bc): more undefined references to `ucnv_close_55' follow
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlCharEncFirstLineInt':
(.text+0x2f6e): undefined reference to `ucnv_convertEx_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlCharEncFirstLine':
(.text+0x3270): undefined reference to `ucnv_convertEx_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlCharEncFirstLineInput':
(.text+0x365a): undefined reference to `ucnv_convertEx_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlCharEncInput':
(.text+0x3a47): undefined reference to `ucnv_convertEx_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlCharEncInFunc':
(.text+0x3de7): undefined reference to `ucnv_convertEx_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o):(.text+0x4197): more undefined references to `ucnv_convertEx_55' follow
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlCharEncCloseFunc':
(.text+0x4bb0): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlCharEncCloseFunc':
(.text+0x4bba): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlCharEncCloseFunc':
(.text+0x4bdd): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlCharEncCloseFunc':
(.text+0x4be7): undefined reference to `ucnv_close_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(encoding.o): In function `xmlByteConsumed':
(.text+0x4f2d): undefined reference to `ucnv_convertEx_55'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlGzfileOpenW':
(.text+0x2b7): undefined reference to `gzdopen'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlGzfileOpenW':
(.text+0x2f8): undefined reference to `gzopen64'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlGzfileOpen':
(.text+0x79c): undefined reference to `gzdopen'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlGzfileOpen':
(.text+0x825): undefined reference to `gzopen64'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlGzfileOpen':
(.text+0x8ae): undefined reference to `gzopen64'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlGzfileOpen':
(.text+0x92a): undefined reference to `gzdopen'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlCreateZMemBuff':
(.text+0xa4a): undefined reference to `deflateInit2_'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlCreateZMemBuff':
(.text+0xa61): undefined reference to `crc32'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlCreateZMemBuff':
(.text+0xafe): undefined reference to `deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlCreateZMemBuff':
(.text+0xb7d): undefined reference to `deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlGzfileWrite':
(.text+0x10f2): undefined reference to `gzwrite'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlGzfileClose':
(.text+0x1645): undefined reference to `gzclose'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlGzfileRead':
(.text+0x20f2): undefined reference to `gzread'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `__xmlParserInputBufferCreateFilename':
(.text+0x51d7): undefined reference to `gzdirect'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlIOHTTPWrite':
(.text+0x6806): undefined reference to `deflate'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlIOHTTPWrite':
(.text+0x6878): undefined reference to `deflate'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlIOHTTPWrite':
(.text+0x69aa): undefined reference to `crc32'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlFreeHTTPWriteCtxt':
(.text+0x6fc7): undefined reference to `deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlIOHTTPCloseWrite':
(.text+0x7841): undefined reference to `deflate'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlIO.o): In function `xmlIOHTTPCloseWrite':
(.text+0x79a5): undefined reference to `deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(nanohttp.o): In function `xmlNanoHTTPFreeCtxt':
(.text+0x40a): undefined reference to `inflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(nanohttp.o): In function `xmlNanoHTTPRead':
(.text+0x110f): undefined reference to `inflate'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(nanohttp.o): In function `xmlNanoHTTPMethodRedir':
(.text+0x1f89): undefined reference to `inflateInit2_'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o): In function `xmlSchemaDateNormalize':
(.text+0x22cb): undefined reference to `floor'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o): In function `xmlSchemaDateNormalize':
(.text+0x230b): undefined reference to `floor'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o): In function `xmlSchemaDateNormalize':
(.text+0x2384): undefined reference to `floor'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o): In function `xmlSchemaDateNormalize':
(.text+0x23df): undefined reference to `floor'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o): In function `xmlSchemaDateNormalize':
(.text+0x241a): undefined reference to `floor'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o):(.text+0x2456): more undefined references to `floor' follow
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o): In function `xmlSchemaGetCanonValue':
(.text+0xb84e): undefined reference to `trunc'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o): In function `xmlSchemaGetCanonValue':
(.text+0xb89a): undefined reference to `trunc'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o): In function `xmlSchemaGetCanonValue':
(.text+0xb8f3): undefined reference to `floor'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xmlschemastypes.o): In function `xmlSchemaGetCanonValue':
(.text+0xb94c): undefined reference to `floor'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `xz_head':
(.text+0x69e): undefined reference to `lzma_auto_decoder'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `xz_head':
(.text+0x706): undefined reference to `inflateInit2_'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `xz_head':
(.text+0x76e): undefined reference to `lzma_properties_decode'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `xz_head':
(.text+0xa1b): undefined reference to `inflateReset'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `xz_head':
(.text+0xa26): undefined reference to `crc32'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `xz_decomp':
(.text+0x11a0): undefined reference to `lzma_code'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `xz_decomp':
(.text+0x1209): undefined reference to `crc32'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `xz_decomp':
(.text+0x12d2): undefined reference to `inflate'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `xz_decomp':
(.text+0x14c0): undefined reference to `crc32'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `__libxml2_xzclose':
(.text+0x1f95): undefined reference to `lzma_end'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.a(xzlib.o): In function `__libxml2_xzclose':
(.text+0x1fc8): undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o '/app/bin/bootstrap'  -rdynamic -static  -lxml2 `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 -lgc -lpthread /usr/share/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`

A quick investigation turned out, that there is no static libzma available under ubuntu.

Is there any easy workaround except building that yourself via an own docker image yourself, in case I missed something?

Thanks for any help!

–Alex

I have not yet solved this issue, but one can install liblzma-dev after running apt-get update in the docker container. Then one can add --link-flags -llzma to the crystal build, but there are still compilation exceptions, slightly different ones though.

I found some issues with static linking under ubuntu after some googling, but did not yet have more time to follow those up and if that would be the cause.

tried fedora, debian, ubuntu docker images and so far I was not able to create a static binary with any of those using the packages from the official distribution. Looks like my next try will be a manual crystal build on any of those platforms.

Static linking is only supported on musl distributions like alpine linux. I suggest you use alpine edge, then it’s easy and usually works out the box. They have crystal in the repos so you can just apk install crystal. You should read this.

1 Like

Hey,

weeeeeeee, that was it! Thanks so much! Did I miss that tiny bit in the documentation?

Anyway, I am now able to compile static code including the aws dependency and run it via AWS lambda… on to the next thing!

–Alex

Yep! Redirecting... :)

I’m glad you got it working!

2 Likes