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

Compiling two sets of files separately fails to link on Linux #877

Open
Jhynjhiruu opened this issue Sep 28, 2023 · 0 comments
Open

Compiling two sets of files separately fails to link on Linux #877

Jhynjhiruu opened this issue Sep 28, 2023 · 0 comments

Comments

@Jhynjhiruu
Copy link

Hello,
I'm trying to use cc-rs to build some code that's in two well-defined sections: some library code, distributed as source, and another library that wraps the first library.
To me, the logical way to implement this in my build.rs is by using two instances of cc::Build, one for the first library and one for the second. This works completely fine under Windows.
However, when testing the build on Linux (both on Arch Linux on a laptop and Ubuntu 22.04.2 through WSL2 on my PC), the build fails to link. For some reason, symbols in the first library aren't being found properly, so the second library is full of undefined references. Adding shared_flag(true) doesn't seem to do anything.
I've created a minimal example that demonstrates this using two C files. My actual project is C++, but the exact same issue occurs.
Interestingly, I was able to work around the issue - by adding .link_lib_modifier("+whole-archive") to the first library. This obviously isn't ideal, as I'd prefer to avoid bloating the final binary if at all possible, but it does suggest that perhaps the issue is related to dead code elimination. I'm mainly just confused about why the behaviour is different on Windows.
Am I being extremely silly and missing an obvious flag to make this magically work? Is this use case simply not supported?

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

1 participant