Anki build on mac fails at link time

I am using MacOS 11.1 (Big Sur) with python 3.8.2 (via pyenv-virtualenv). I will confess that it was installed with homebrew, and although I am aware that use of homebrew python is not technically supported, it really seems like there ought to be a way to get that to work.

Specifically, the error I get is:

$ ./run
INFO: Analyzed target //qt:runanki (568 packages loaded, 17391 targets configured).
INFO: Found 1 target...
INFO: From Compiling Rust bin write_fluent_proto (2 files) [for host]:
error: linking with `external/local_config_cc/cc_wrapper.sh` failed: exit code: 1
|
= note: "external/local_config_cc/cc_wrapper.sh" "-m64" "-arch" "x86_64" "-L" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.0.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.1.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.10.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.11.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.12.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.13.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.14.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.15.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.2.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.3.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.4.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.5.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.6.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.7.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.8.rcgu.o" "bazel-out/host/bin/rslib/write_fluent_proto.write_fluent_proto.7rcbfp3g-cgu.9.rcgu.o" "-o" "bazel-out/host/bin/rslib/write_fluent_proto" "bazel-out/host/bin/rslib/write_fluent_proto.4jjnjut7mc3yssaa.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib" "-L" "bazel-out/host/bin/external/raze__fluent_syntax__0_10_0" "-L" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/execroot/net_ankiweb_anki/bazel-out/host/bin/external/raze__fluent_syntax__0_10_0/libfluent_syntax-1886982365.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libstd-688c1376a25c049d.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-078f89c2cdb6d46b.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libobject-fec020208bc1ad3c.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-38540dcacc9fd218.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libgimli-6f613179f618c598.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-4d1a5d7118aaeaf2.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-d88fab3b1b9d8356.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-a21754532a052f2f.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libunwind-2e9ebc4127641a96.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-82d0f961232a05ca.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/liblibc-370b1b71f08bac3c.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/liballoc-816106c1f35f5421.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-20f3a030f1a56a86.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libcore-60333aa00936c5ce.rlib" "/private/var/tmp/_bazel_jrporter/478ccab7133ce336085a049382f6aafb/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-116aaeaea873ef94.rlib" "-lSystem" "-lresolv" "-lc" "-lm" "-undefined" "dynamic_lookup" "-headerpad_max_install_names" "-lstdc++" "-lm"
  = note: ld: library not found for -lstdc++
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: aborting due to previous error

ERROR: /Users/jrporter/projects/anki/rslib/BUILD.bazel:150:12: output 'rslib/write_fluent_proto' was not created
ERROR: /Users/jrporter/projects/anki/rslib/BUILD.bazel:150:12: not all outputs were created or valid
Target //qt:runanki failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /Users/jrporter/projects/anki/qt/BUILD.bazel:119:10 not all outputs were created or valid
INFO: Elapsed time: 61.999s, Critical Path: 21.46s
INFO: 150 processes: 108 internal, 34 darwin-sandbox, 8 worker.
FAILED: Build did NOT complete successfully

Am I missing something obvious here? I’m totally new to bazel, but it’s my strong suspicion maybe it’s not detecting my homebrew python, and is instead using my system python (based on the comment in the mac develoment docs that it fails at link time when that’s the issue).

Anyone with more familiarity with basel have any thoughts?

Thanks!

That doesn’t look related to Python. Did you install XCode and start it at least once, allowing it to install additional components? If so, perhaps running xcode-select --install in a terminal will help?

Thanks for the quick response!

Did you install XCode and start it at least once

I had not, but I have now done so and it doesn’t change the error.

perhaps running xcode-select --install in a terminal

Unfortunately this seems to have been broken in Big Sur?

$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

I did also try to go into Software Update, but it didn’t find anything.

Some googling suggests I may need to downgrade my xcode command line tools? That’s fine for me for now (as soon as I figure out how to actually do it) but it sounds like libstd++ was depricated with xcode 8 (in favor of libc++), and they’ve removed it in xcode 10.

I don’t know too much about the C++ scene… do you have any recs apart from just installing the older xcode version?

I’m using the latest XCode on Big Sur here without issues. You could try a fresh checkout and fresh build after you did the XCode install step to see if that helps. If it doesn’t, the following thread looks related:

(with a fresh checkout you may need a different folder name; you could alternatively use ‘bazel clean --expunge’ to clean things up)

bazel clean --expunge

This (in combination with the xcode app install from the app store) did it! The expunge is crucial… I just rm -rf’d the directory and (as you obviously already know) that’s not sufficient.

Hooray!

Thanks!

I had this issue and upgrading to bazel 5.1.1 helped. I’m proposing PR#1808 to fix this issue for everyone.