1

I have an external library ace.so.

cc_library(
    name='ace',
    hdrs=glob(['path/to/ace/**']),
    srcs=['path/to/ace.so'],
)

How do I go about linking to that library with bazel? I know a colon can be used when invoking gcc/g++ directly, but I'm not sure how to get the same behavior from bazel.

  • I tried adding -l:ace.so (also -Wl,-l:ace.so) to copts but it seems bazel doesn't pass that to gcc or add it to the @ file used for linker args.
  • I tried nocopts='-lace.so' in combination with linkopts=['-l:ace.so']. No luck.
  • I also tried cc_import instead of cc_library, but that didn't work either.

I've read the Importing precompiled C++ libraries doc, but I didn't see anything about using libs with an arbitrary prefix - or with no prefix.

As a temporary fix, I've added a symlink libace.so pointing to ace.so and changed the srcs line to match. While this works, I'd much rather convince bazel to use the lib as is.

Mark
  • 1,035
  • 2
  • 11
  • 24
  • I've tried, but did not get through. Could you, please, correct your post. You are referring to `:` as semicolon in the first paragraph bellow code block, but it is a colon. – Ondrej K. Jun 25 '18 at 16:17
  • @OndrejK. Fixed. I realized I'd made a mistake after posting, but didn't see it as serious enough to bother fixing - it's quite obvious from the linked page, after all. – Mark Jul 05 '18 at 14:10

1 Answers1

1

Looking around how information about libraries is being collected and passed around, I am afraid this (assumption that "plain" dynamic libraries are prefixed with lib and libfoo.so can be given as -lfoo is fairly hard coded at the moment. The same would not be true of it was considered a "versioned" (matches a pattern "^.+\\.so(\\.\\d+)+$") dynamic library, which would be passed as -l:foo.so.1. But unfortunately that does not really help you, because you'd still need to employ a similar workaround and create a fiction of versioning to boot. That said, as long as your solib filenames are given, the symlink sounds like a reasonably sane workaround.

Ondrej K.
  • 8,841
  • 11
  • 24
  • 39