Reputation: 19431
I'm learning Bazel, because I have to use it at work. I have a simple build rule that creates a library from a single file and I would like control what is exported by the linker by using a linker version file. (I'm on Linux)
So I tried:
cc_library (
name ="thelib",
srcs = ["lib.cpp"],
linkopts = ["-Wl,--version-script,lib.ver"]
)
And it tells me "No such file or directory".
What have I tried:
bazel info --show_make_env
it showed me a variable called workspace
so I then tried $(workspace)/lib/lib.ver
but then it says $(workspace) not defined
so Bazel is a liar.-fvisiblity=hidden
and export using __attribute__
to export is not an option because the standard C++ library overrides it and forces exporting of the symbols you don't want to appear on the interface (the library is used using extern "C" interface only I don't want any other garbage appear on it).At this point I completely ran out of ideas. Any help is appreciated.
Upvotes: 1
Views: 1974
Reputation: 20520
First of all, shared libraries are generally declared with cc_binary
in conjunction with its linkshared
attribute rather than cc_library
. This is counterintuitive but reflects the intention that cc_binary
creates a transitive link while cc_library
declares an intermediate library. (More adventurous folks may try out cc_shared_library
Second of all, it's possible to use version scripts (and other linker scripts) by using them in linkopts
and declaring them as a dependency in deps
.
So, all together:
cc_binary(
name = 'mylib.so',
linkshared = True,
srcs = ['mylib.cc'],
linkopts = ['-Wl,-version-script=$(location version-script.lds)'],
deps = [
'version-script.lds',
]
)
Upvotes: 2