-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android NDK: Default linker flags that might save people pain #10837
Comments
@cpsauer I'm upgrading from bazel 0.23.2 to 1.2.1 and I'm also running it into what I think are issues related to linker flags. A build that used to work on 0.23.3 now breaks on 1.2.1 with the following error:
Did one of your build surprises look like this? I'm at a loss on what to do here. |
Yup! Add -ldl to linkopts to link libdl. dl_iterate_phdr looks like a dl (dynamic library) call to me! |
No still doesn't work. I added -ldl at my top level BUILD file and every BUILD file that builds any C++ and it still fails. I don't know where else to go from here. The error message does not reference any of my code. Only the toolchain. |
(Replied to @shamtron's question in the separate issue he filed.) |
Another thought, after some more time working around/with NDK builds: In the meantime, if anyone wants an easy fix for all this--just a rule you depend on and if fixes linker defaults plus android pthread issue--lmk. Happy to share. |
These flags were in Google's internal NDK toolchain, newly released by @ahumesky as https://github.com/bazelbuild/rules_android_ndk, to replace the existing. It makes me so happy to close this. I bet the change will save pain for almost everyone booting up on the NDK with Bazel! |
Hi wonderful Bazel team,
I was playing around with the Android NDK. Along the way, I ran into a couple of build surprises that I think could be easily fixed for other people going down the same path, with just a change to the default linker options.
In particular, I think adding ["--no-undefined", "-lm", "-ldl"] to the default linkopts would make things easier for people. Reasoning below:
First, the linker seems to have undefined errors off by default (!) and will therefore happily produce .so's that can't be loaded... We can make this trigger a linker error, as you'd expect on other platforms, by adding --no-undefined.
And second, the basics you'd expect, like the math part of libc (libm) and shared library support (libdl) aren't linked by default, though libc is, and its headers refer to symbols in those libraries. Adding -lm and -ldl fixes the surprises there (which are themselves much easier to find once --no-undefined has been passed). Maybe we intentionally don't want to link to those implicitly, but I'm guessing we do, since bazel automatically links to other NDK libraries, and I don't think you normally have to manually link in libm or libdl on other platforms.
Thanks for your consideration,
Chris
The text was updated successfully, but these errors were encountered: