You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When building a binary rust project in a workspace with a crate that was using cxx, I encountered linker errors for missing libstdc++ symbols when building with clang 16 that I had not encountered in older versions of clang.
...
= note: Undefined symbols for architecture arm64:
"___gxx_personality_v0", referenced from:
void rust::cxxbridge1::panic<std::invalid_argument>(char const*) in libcxx-7d0d833a32f757b8.rlib(cxx.o)
...
I thought this was odd as I noticed "-lc++" present in the cargo linker line, yet the linker seemed to not be operating as clang++, but rather clang.
Additional Info
macOS 14.2.1 (23C71)
[[package]]
name = "cxx"
version = "1.0.107"
...
[[package]]
name = "cxx-build"
version = "1.0.107"
...
❯ cc --version
clang version 16.0.6
Target: arm64-apple-darwin
Thread model: posix
InstalledDir: /nix/store/a5v30qll5i02vr9y97bk1rdx3mm6kvlm-clang-16.0.6/bin
Workaround
I was able to successfully link the binary by setting RUSTFLAGS="-C link-args=-xc++" or adding the following to .cargo/config.toml:
[target.aarch64-apple-darwin]
# lld not necessary for workaround
rustflags = ["-C", "link-arg=-fuse-ld=lld", "-C", "link-arg=-xc++"]
What Didn't Work
Using .cpp(true) or println!("cargo:rustc-link-arg=-xc++"); in the build.rs for the crate using cxx, as the linker issue was only encountered when building the binary which depended on that crate.
The text was updated successfully, but these errors were encountered:
Description
When building a binary rust project in a workspace with a crate that was using
cxx
, I encountered linker errors for missing libstdc++ symbols when building with clang 16 that I had not encountered in older versions of clang.I thought this was odd as I noticed
"-lc++"
present in the cargo linker line, yet the linker seemed to not be operating asclang++
, but ratherclang
.Additional Info
Workaround
I was able to successfully link the binary by setting
RUSTFLAGS="-C link-args=-xc++"
or adding the following to.cargo/config.toml
:What Didn't Work
Using
.cpp(true)
orprintln!("cargo:rustc-link-arg=-xc++");
in thebuild.rs
for the crate usingcxx
, as the linker issue was only encountered when building the binary which depended on that crate.The text was updated successfully, but these errors were encountered: