Undefined symbol when linking to a shared library produced by native.rule code generation
blackjack opened this issue · 0 comments
Description of the problem / feature request:
When using native.rule
to generate some C++ code I get undefined reference error when linking tests to shared library which is using that generated code.
Generated file names are not known beforehand, and the output is collected via declare_directory()
.
The generated shared library contains no symbols from object files (if you inspect it via nm
), and linker command line shows that object files are linked inside --start-lib
and --end-lib
block.
Conversely, if you generate same sources via genrule
with explicit output file names, everything works fine, object files are not surrounded by start/end-lib and symbols are present in generated shared library
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
See example.tar.gz file for minimal example.
You can build it using command line bazel build //:testCodegen --//:impl=<1 or 2>
In case of
bazel build //:testCodegen --//:impl=1
sources are generated via native.rule and linker displays undefined symbol hello_world() error
In case of
bazel build //:testCodegen --//:impl=2
sources are generated via genrule and test compiles just fine
What operating system are you running Bazel on?
Debian 11 (Bullseye), amd64
What's the output of bazel info release
?
release 7.0.0
What version of rules_cc do you use? Can you paste the workspace rule used to fetch rules_cc? What other relevant dependencies does your project have?
Default version
What Bazel options do you use to trigger the issue? What C++ toolchain do you use?
reproducible with clang 17 and Clang 13 with lld linker
Have you found anything relevant by searching the web?
Reached slack channel and was advised to open a ticket
Any other information, logs, or outputs that you want to share?
See attachment