[Haskell-cafe] Static linking against X11

Brandon Allbery allbery.b at gmail.com
Wed May 1 21:07:13 UTC 2019


The problem is that static archives can't declare implicit dependencies: if
you link dynamically, libX11.so will implicitly depend on libxcb.so, but if
you link statically you must also explicitly link against -lxcb.

On Wed, May 1, 2019 at 5:00 PM Vanessa McHale <vanessa.mchale at iohk.io>
wrote:

> Hi all,
>
> I'm trying to cross-compile xmobar for aarch64-linux-gnu. The cross
> compiler that comes with my version of Ubuntu works with a later GLIBC
> than the host platform, so I figured I'd make a static executable
> instead - this approach had worked with e.g. cabal-install.
>
> Unfortunately, I get the following:
>
> Resolving dependencies...
> Build profile: -w ghc-8.6.4 -O1
> In order, the following will be built (use -v for more details):
>  - xmobar-vanessa-0.1.0.0 (exe:xmobar) (first run)
> Preprocessing executable 'xmobar' for xmobar-vanessa-0.1.0.0..
> Building executable 'xmobar' for xmobar-vanessa-0.1.0.0..
> Linking
>
> /home/vanessa/programming/haskell/done/xmobar-vanessa/dist-newstyle/build/aarch64-linux/ghc-8.6.4/xmobar-vanessa-0.1.0.0/x/xmobar/build/xmobar/xmobar
> ...
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> /usr/local/lib/aarch64-linux-gnu-ghc-8.6.4/rts/libHSrts.a(Linker.o): in
> function `internal_dlopen':
>
> /home/vanessa/cross/ghc-8.6.4/rts/Linker.c:600:0: error:
>      warning: Using 'dlopen' in statically linked applications requires
> at runtime the shared libraries from the glibc version used for linking
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /home/vanessa/.cabal/store/ghc-8.6.4/network-3.1.0.0-b60cf17d11d7eda024959ae28f710f94d7565bcd8e3372f04f32d2600769c2c1/lib/libHSnetwork-3.1.0.0-b60cf17d11d7eda024959ae28f710f94d7565bcd8e3372f04f32d2600769c2c1.a(HsNet.o):
> in function `hsnet_getaddrinfo':
> HsNet.c:(.text+0x10): warning: Using 'getaddrinfo' in statically linked
> applications requires at runtime the shared libraries from the glibc
> version used for linking
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(xcb_io.o):
> in function `require_socket':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:68:0: error:
>      undefined reference to `xcb_take_socket'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(xcb_io.o):
> in function `poll_for_event':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:245:0: error:
>      undefined reference to `xcb_poll_for_event'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:243: undefined
> reference to `xcb_poll_for_queued_event'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(xcb_io.o):
> in function `poll_for_response':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:284:0: error:
>      undefined reference to `xcb_poll_for_reply64'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(xcb_io.o):
> in function `_XSend':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:499:0: error:
>      undefined reference to `xcb_writev'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(xcb_io.o):
> in function `_XEventsQueued':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:364:0: error:
>      undefined reference to `xcb_connection_has_error'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(xcb_io.o):
> in function `_XReadEvents':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:441:0: error:
>      undefined reference to `xcb_connection_has_error'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:400: undefined
> reference to `xcb_wait_for_event'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(xcb_io.o):
> in function `_XAllocIDs':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:549:0: error:
>      undefined reference to `xcb_generate_id'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(xcb_io.o):
> in function `_XReply':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_io.c:609:0: error:
>      undefined reference to `xcb_wait_for_reply64'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(ClDisplay.o):
> in function `XCloseDisplay':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/ClDisplay.c:71:0: error:
>      undefined reference to `xcb_disconnect'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(OpenDis.o):
> in function `OutOfMemory':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/OpenDis.c:705:0: error:
>      undefined reference to `xcb_disconnect'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(OpenDis.o):
> in function `XOpenDisplay':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/OpenDis.c:255:0: error:
>      undefined reference to `xcb_get_setup'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/OpenDis.c:498: undefined
> reference to `xcb_get_maximum_request_length'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/lib/../lib/libX11.a(xcb_disp.o):
> in function `_XConnectXCB':
>
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_disp.c:69:0: error:
>      undefined reference to `xcb_parse_display'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_disp.c:76: undefined
> reference to `xcb_connect_to_display_with_auth_info'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_disp.c:81: undefined
> reference to `xcb_get_file_descriptor'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_disp.c:84: undefined
> reference to `xcb_generate_id'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_disp.c:92: undefined
> reference to `xcb_connection_has_error'
>
> /usr/lib/gcc-cross/aarch64-linux-gnu/8/../../../../aarch64-linux-gnu/bin/ld:
> /tmp/cpkg-2c6d48cdbb4678ca/libX11-1.6.7/src/xcb_disp.c:78: undefined
> reference to `xcb_connect'
> collect2: error: ld returned 1 exit status
> `aarch64-linux-gnu-gcc' failed in phase `Linker'. (Exit code: 1)
>
> I looked in libX11.a with
>
> nm /usr/aarch64-linux-gnu/lib/libX11.a | rg 'xcb_take_socket'
>
> which yields
>
>                  U xcb_take_socket
>
>
> which, as I understand, means that something is screwed up in the X11
> static linking (but I know less about systems programming and linkers
> than Haskell).
>
> Does anyone know how to fix such a problem?
>
> Cheers,
> Vanessa McHale
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.



-- 
brandon s allbery kf8nh
allbery.b at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190501/1f1bde98/attachment.html>


More information about the Haskell-Cafe mailing list