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

Building binaries using clang 16 on macOS results in linker error #1307

Open
cirla opened this issue Jan 18, 2024 · 0 comments
Open

Building binaries using clang 16 on macOS results in linker error #1307

cirla opened this issue Jan 18, 2024 · 0 comments

Comments

@cirla
Copy link

cirla commented Jan 18, 2024

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.

...
  = 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.

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