c++versioncluster-computingbazeldynamic-library

failed to find version script file when linking a dynamic library by using bazel cluster


I was building a shared/dynamic library by using bazel. The rules in Build file are like below

cc_library(
    name = "a",
    srcs = ["a.cc"]
)

filegroup(
    name = "vis_ld",
    srcs = ["tool/vis.ld"]
)

cc_library(
    name = "b",
    hdrs = ["b.h"],
    srcs = ["b.cc"],
    deps = [":a"],
)

cc_binary(
    name = "libgeta.so",
    deps = [":b"],
    linkshared = True,
    linkopts = [
        "-Wl,--version-script,","$(location :vis_ld)"
    ],
    data = [":vis_ld"]
)

The libgeta.so is target binary file. As we known from the rule, there exists a version script file that limits the exported symbols. Here's the wired thing, if I built libgeta.so locally, it works fine. When I tried to build with bazel cluster, it fails with following error.

/opt/rh/devtoolset-7/root/usr/bin/ld.gold: error: cannot open tool/vs.ld: No such file or directory
/opt/rh/devtoolset-7/root/usr/bin/ld.gold: fatal error: unable to parse version script file tool/vs.ld
collect2: error: ld returned 1 exit status

the bazel version I was using is 0.24.1.

It has confused me for days, please help. Thanks!

I tried to generate vs.ld file with Rule genrule at compile-time, but it does not work.


Solution

  • The version script needs to go into the deps attribute of the cc_binary rather than data.

    (Also, Bazel 0.24.1 is very old.)