gcc-toolchain icon indicating copy to clipboard operation
gcc-toolchain copied to clipboard

Error during bazel build: cannot find /usr/lib/libc.so.6

Open ArmaanT opened this issue 3 years ago • 4 comments

I've been running into an issue where I get the following error when trying to use this toolchain to build zlib:

/home/atobaccowalla/.cache/bazel/_bazel_atobaccowalla/49400f0e8b5fdbc2448f09cd587fc4d3/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: cannot find /usr/lib/libc.so.6
/home/atobaccowalla/.cache/bazel/_bazel_atobaccowalla/49400f0e8b5fdbc2448f09cd587fc4d3/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: cannot find /usr/lib/libc_nonshared.a
/home/atobaccowalla/.cache/bazel/_bazel_atobaccowalla/49400f0e8b5fdbc2448f09cd587fc4d3/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: cannot find /usr/lib/ld-linux-x86-64.so.2

None of those files exist on my machine in /usr/lib, but they do exist in /usr/lib64 (ex /usr/lib64/libc.so.6):

➜ find /usr -name 'libc.so.6'
/usr/lib64/libc.so.6

That being said, I'm not sure if this toolchain is (or should be) checking paths on my machine rather than only looking inside the downloaded sysroot which contains those files in the expected location:

➜ find /home/atobaccowalla/.cache/bazel/_bazel_atobaccowalla/49400f0e8b5fdbc2448f09cd587fc4d3/execroot/gcc-toolchain-sample/external/sysroot_x86_64/ -name 'libc.so.6'
/home/atobaccowalla/.cache/bazel/_bazel_atobaccowalla/49400f0e8b5fdbc2448f09cd587fc4d3/execroot/gcc-toolchain-sample/external/sysroot_x86_64/usr/lib/libc.so.6

I'm including the full output I get when trying to build here and I've also created a minimal reproduction repo here.

ArmaanT avatar Oct 10 '22 21:10 ArmaanT

After experimenting around a bit more, everything works as expected if I swap the configure_make in zlib.BUILD with the following:

cc_library(
    name = "zlib",
    srcs = glob(["*.c"]),
    hdrs = glob(["*.h"]),
    copts = [
        "-Dverbose=-1",
    ],
    includes = ["."],
    visibility = ["//visibility:public"],
)

I wonder if there's some weird interaction going on between the toolchain and rules_foreign_cc

ArmaanT avatar Oct 11 '22 18:10 ArmaanT

@ArmaanT I just wanted to give you a heads-up that the primary maintainer for this repo will not be available for a few weeks. They have the expertise to best help with this issue. Sorry for the delay.

cgrindel avatar Oct 18 '22 14:10 cgrindel

No problem at all. Thanks for the heads up!

ArmaanT avatar Oct 18 '22 14:10 ArmaanT

@ArmaanT Sorry for the delay. This got lost on my list when I came back. Did you resolve this? The problem you are hitting is that your Linux distribution uses /usr/lib64 instead of the more common /usr/lib. This behaviour is controlled by the following line:

https://github.com/aspect-build/gcc-toolchain/blob/22862ac5637edc946a2d03f7fcc413b8c897b44f/sysroot/Dockerfile#L155

What distro are you using?

f0rmiga avatar Feb 01 '23 22:02 f0rmiga