I have various tool chain directories on my linux machine for compiling under specific compiler versions. I have a problem where the linker (in the tool chain dir) is selecting a library file from the native machine (/lib, for example) rather than the one in the tool chain (/toolchain/lib/...). This results in various linker errors such as:

/opt/foo/cross_x86_64_v9b/lib/gcc/x86_64-linux/9.2.0/../../../../bin/x86_64-linux-ld: /lib/x86_64-linux-gnu/libxmlrpc_client.so.3: undefined reference to `curl_easy_getinfo@CURL_OPENSSL_4'

The link is failing because it is linking /lib/x86_64-linux-gnu/libxmlrpc_client.so.3 (native file on my Ubuntu) instead of /opt/foo/cross_x86_64_v9b/lib64/libxmlrpc_client.so.3 (tool chain version).

Here's the search paths as far as I can figure:

/opt/foo/cross_x86_64_v9b/bin/x86_64-linux-ld --verbose | grep SEARCH_DIR
SEARCH_DIR("/opt/foo/cross_x86_64_v9b/x86_64-linux/lib64"); SEARCH_DIR("/opt/foo/cross_x86_64_v9b/lib64"); SEARCH_DIR("/opt/foo/cross_x86_64_v9b/lib"); SEARCH_DIR("/opt/foo/cross_x86_64_v9b/x86_64-linux/lib");

If I remove the libxml... files from /lib/x86_64-linux-gnu then the link succeeds, so somehow that path is being searched ahead of the SEARCH_DIR above. All the system libraries being linked should be under /opt/foo/cross_x86_64_v9b.

Neither LD_PATH nor LD_LIBRARY_PATH are defined in my environment. Why is the linker searching /lib before /opt/foo/cross_x86_64_v9b/lib64/? How can I correct this?

  • Does your build use pkg-config? Jan 4, 2023 at 22:15
  • @StephenKitt: No, we have a complex makefile setup.
    – kfank
    Jan 5, 2023 at 0:26

1 Answer 1


Two quick ideas for you to consider:

  1. The lib path you specify during the configure for binutils is added to this list of SEARCH_DIR paths. I'm not sure exactly where it is placed in that order, but you can easily verify this after including the option while configuring and installing.

  2. Your search paths can be manually edited in libc.so and libm.so. This might cause other errors though so be careful...

    cp -uv /opt/foo/cross_x86_64_v9b/lib/libc.so{,.orig}
    cp -uv /opt/foo/cross_x86_64_v9b/lib/libm.so{,.orig}
    sed -e 's@/path1@/path2@g' /opt/foo/cross_x86_64_v9b/lib/libc.so.orig > /opt/foo/cross_x86_64_v9b/lib/libc.so
    sed -e 's@/path1@/path2@g' /opt/foo/cross_x86_64_v9b/lib/libm.so.orig > /opt/foo/cross_x86_64_v9b/lib/libm.so
    diff /opt/foo/cross_x86_64_v9b/lib/libc.so{,.orig}
    diff /opt/foo/cross_x86_64_v9b/lib/libm.so{,.orig}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .