cxx
cxx copied to clipboard
Failed to build on Macbook M1
Hi there,
I'm trying to cargo build
with cxx as dependencies
[dependencies]
cxx = "1.0.94"
But facing error: error: failed to run custom build command for
cxx v1.0.94`
error occurred: Command "c++" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-Wall" "-Wextra" "-o" "/Users/nvtrang/code/starknet/cxx/target/release/build/cxx-090a4ae2985bda90/out/src/cxx.o" "-c" "src/cxx.cc" with args "c++" did not execute successfully (status code exit status: 1).
I have these Homebrew Fomulae:
==> Formulae
autoconf freetype glib libpng libxdmcp lzo openssl@3 [email protected] tcl-tk zstd
ca-certificates gdbm gmp libtiff libxext m4 pcre2 [email protected] tree
cmake gettext graphite2 libx11 libxrender make pixman readline xorgproto
coreutils giflib icu4c libxau little-cms2 mpdecimal pkg-config six xz
fontconfig git-lfs jpeg-turbo libxcb lz4 [email protected] protobuf sqlite z3
==> Casks
raycast temurin
I appreciate any help. Thank you
There must be more error output somewhere. This just tells you it failed.
Anyway, I use Xcode command line tools, which provide clang, and it works just fine on M1 Mac.
running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "-arch" "arm64" "-Wall" "-Wextra" "-o" "/Users/vany/b/unpack/target/debug/build/cxx-e088f39d86964a61/out/src/cxx.o" "-c" "src/cxx.cc"
cargo:warning=In file included from src/cxx.cc:1:
cargo:warning=src/../include/cxx.h:24:1: warning: inline namespaces are a C++11 feature [-Wc++11-inline-namespace]
cargo:warning=inline namespace cxxbridge1 {
cargo:warning=^
cargo:warning=src/../include/cxx.h:36:14: warning: 'final' keyword is a C++11 extension [-Wc++11-extensions]
cargo:warning=class String final {
cargo:warning= ^
cargo:warning=src/../include/cxx.h:38:11: error: expected ';' at end of declaration list
cargo:warning= String() noexcept;
cargo:warning= ^
cargo:warning= ;
unpack$c++ --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
!!!
export CXXFLAGS="c++11"
helps ... but why?
may be this will help https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes
We experience the same problem (see the link above this comment). It seems that c++
is called without the -std=c++11
flag, although it should be.
You can add: https://github.com/dtolnay/cxx/blob/c96397721c2fd61b0809ca4c38d9c5ef9008b25a/gen/build/src/lib.rs#L134
This flag is already present in all crates that I control. Also notice that the compiler error appears when compiling src/cxx.cc
, which is coming from one of the cxx
crates. Where is this file compiled? I believe - I might be wrong though - there's a problem.
Another observation: I've only encountered this for
$ c++ --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
which is the same platform reported in https://github.com/dtolnay/cxx/issues/1217#issuecomment-1607779334. On my desktop PC with a GCC compiler the -std=c++11
switch is present when compiling src/cxx.cc
.
I now believe this to be a problem in cc
, specifically this one: https://github.com/rust-lang/cc-rs/issues/730. This Issue is then probably a duplicate of https://github.com/dtolnay/cxx/issues/952.
Since both Issues have been marked 'fixed', but the newest release of cc
, in which the fixes are included, has been yanked I see two possibilities:
- wait for
cc
to release a newer version. In that case I would appreciate keeping this Issue open to let users know this is a problem and to avoid duplicate Issues - set the C++ standard using the newly introduced
cc::Build::std()
method instead of usingcc::Build::is_flag_supported()
here: https://github.com/dtolnay/cxx/blob/dbd370482772df3bc5de18de4fd949c3a78bf279/build.rs#L9-L15 However, I haven't had a look a thestd
method implementation. It's possible it usesis_flag_supported
internally at some point and therefore suffers from the same problem. On the other hand, in the long run it's probably best to avoid duplicating the set-the-C++-standard logic in this crate (although technically it was duplicated incc
, I guess). If this is the desired solution, I can volunteer to write a pull request.
With https://github.com/rust-lang/cc-rs/issues/730 being merged I believe this no longer to be a problem. Moreover #1321 and #1322 being merged implements what I suggested in my last comment.
I think this Issue can be closed.
Thank you!