How to correctly give a path to an existing file in linkopts?

521 views
Skip to first unread message

Nicholas Junge

unread,
Mar 14, 2023, 11:07:37 AM3/14/23
to bazel-discuss
Hello Bazel community,

I am trying to compile a C++ library, which recommends supplying information about symbols specifically on macOS by using a linker response file.

The file is already generated, and lives in my repo in a directory directly under base (so the path is something like "a/linker-response-file.sym"). I just cannot figure out how to pass it to the linker as a path that it will understand, and it complains that the file does not exist. I have tried setting the linkopt like so:

cc_library(
  name = "my-lib",
  ...,
  linkopts = select(":macos": {["-Wl,-dead_strip, "-Wl,@a/linker-response-file.sym"], ...})
)
(Note: The @ there is meant to be a clang prefix for indicating a file path, and not Bazel-related.)

I have also attempted to create a filegroup with the response file as a single src, and then use "-Wl,@$(location :filegroup)", but to no avail.

I feel like I am missing something very basic here, and would be happy for guidance. Thank you!

Keith Smiley

unread,
Mar 15, 2023, 12:53:04 PM3/15/23
to Nicholas Junge, bazel-discuss
You have to declare it as an `additional_linker_inputs`. This seems to work in a small test case:

```
filegroup(
    name = "foo",
    srcs = ["foo.txt"],
)

cc_binary(
    name = "main",
    srcs = ["main.cc"],
    additional_linker_inputs = [":foo.txt"],
    linkopts = ["-Wl,@$(location :foo.txt)"],
)
```

--
Keith Smiley


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/63944d57-f10f-491b-ab1d-bb020ff66060n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages