Skip to content
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

The automatic stdc++ linking makes it impossible to statically link stdc++ on Android #310

Closed
tomaka opened this issue Apr 10, 2018 · 3 comments

Comments

@tomaka
Copy link
Contributor

tomaka commented Apr 10, 2018

In order to statically link the standard C++ library, I pass -lc++_static to the linker by tweaking my .cargo/config file, like this:

[target.armv7-linux-androideabi]
linker = "arm-linux-androideabi-clang"
ar = "arm-linux-androideabi-ar"
rustflags = ["-C", "link-arg=-lc++_static", "-C", "link-arg=-lc++abi", "-C", "link-arg=-landroid_support"]

[target.arm-linux-androideabi]
linker = "arm-linux-androideabi-clang"
ar = "arm-linux-androideabi-ar"
rustflags = ["-C", "link-arg=-lc++_static", "-C", "link-arg=-lc++abi", "-C", "link-arg=-landroid_support"]

However cc-rs automatically adds -l stdc++ at the end of the arguments because of the cpp_link_stdlib() method.
For an undetermined reason, this -l stdc++ flag seems to have taken priority over -l c++_static, which means that compiled libraries now depend on c++_shared. The Android build of Parity has recently broken because of that.

Ideally there should be a way to overwrite the default value for cpp_link_stdlib() from the .cargo/config.toml, however that's not really possible.

Do you have any suggestion?

@alexcrichton
Copy link
Member

Can cpp_link_stdlib(None) be used to disable passing this flag?

@tomaka
Copy link
Contributor Author

tomaka commented Apr 11, 2018

Can cpp_link_stdlib(None) be used to disable passing this flag?

Yes, but this would need to be done for every single library that uses cc-rs. I don't think it's the role of each library maintainer to decide to which stdc++ to link to.

@alexcrichton
Copy link
Member

I think at this point yeah that's what it amounts to unfortunately. Nothing works in isolation without linking the standard library.

One other possible alternative would be some sort of env var which cc recognizes and tweaks by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants