Change:
Sorry, I don't have a minimal reproduction repo. The error can be found at It doesn't seem to be able to resolve the required symbols somehow. I can verify that it compiles with the same code on nightly-2022-03-31. <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --:
It passes build on MacOS, but the tests show that a global shared static variable between rust side and C side is wrong.
It's introduced by
I'll check what happens. Either crate gets something wrong with native library dependency order, or some library needs the modifier which is no longer by rustc by default in some cases.
Either crate gets something wrong with native library dependency order, or some library needs the modifier It's actually both. The build script in gets the dependency order wrong. depends on both and , and also depends on , so the linking order should look like . Example of a possible fix: is a C++ library using global C++ constructors. Smoke tests in will fail if those constructors are not run. needs to be linked as whole-archive for the constructors to not be dropped. Unfortunately it's not possible to just add the modifier due to the "linking modifiers and are not compatible with each other when generating rlibs" errors because is a rlib and is the default for libraries. I'm afraid we'll have to revert some changes from and keep as default for some more cases until is easily usable in rlibs.
I guess a topological sorting is necessary to get all dependencies order right.
I change to the link order you suggested, but then the smoke case fails on both MacOS and Linux with the stable toolchain. Changing it to fix the problem on stable though.
Fixed in
FWIW is also affected by this: running worked in nightly-2022-03-30 but fails with a linking error on newer nightlies: Build log:
In case of the fix is to respect dependencies between C and C++ libraries. It doesn't involve the " in rlib" case unfixable by user, so it won't be fixed by
that works perfectly, huge thanks for taking a look :) Do you know why this changed on nightly? I see doesn't have a changelog for items since the last stable release.
Do you know why this changed on nightly? Due to Previously rustc implicitly linked static libraries as whole-archive in some cases (when linking static libraries directly into executables, for example). After we try to not implicitly use whole-archive if possible.

Discussion:
NativeLibKind::Framework { as_needed } => { cmd.link_framework(name, as_needed.unwrap_or(true)) } <del> NativeLibKind::Static { whole_archive, .. } => { </del> <ins> NativeLibKind::Static { whole_archive, bundle, .. } => { </ins> if whole_archive == Some(true) || (whole_archive == None && default_to_whole_archive(sess, crate_type, cmd)) <ins> // Backward compatibility case: this can be a rlib (so `+whole-archive` cannot // be added explicitly if necessary, see the error in `fn link_rlib`) compiled // as an executable due to `--test`. Use whole-archive implicitly, like before // the introduction of native lib modifiers. || (bundle != Some(false) && sess.opts.test) </ins> { cmd.link_whole_staticlib( name,