Skip to content

builtin-libc++ not working on macos #666

@Icantjuddle

Description

@Icantjuddle

I've configure a barebones llvm toolchain via:

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
     cxx_standard = {"": "c++23"},
    stdlib = {"": "builtin-libc++"},
     llvm_version = "21.1.6",
 )
 use_repo(llvm, "llvm_toolchain")
 register_toolchains("@llvm_toolchain//:all")

However when linking my application it appears to be using the system libc++ not the one from the toolchain as it is unable to find symbols used by the version of the standard library, in particular: undefined symbol: std::__1::__hash_memory.

I verified with:
nm -gU /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libc++.tbd 2>/dev/null | grep __hash_memory and nm -gU bazel-whenufree/external/toolchains_llvm++llvm+llvm_toolchain_llvm/lib/libc++.a 2>/dev/null | grep __hash_memory that the symbol is only present in the builtin version of libc++.

Looking in the link params file I see this snippet which looks off to me, I would expect the order in which search paths are added to have the builtin library ahead of the system library so it is preferred:

#... more
-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
-lc++
-lc++abi
-Bdynamic
-Lexternal/toolchains_llvm++llvm+llvm_toolchain_llvm/lib
# ... more

Moving the -Lexternal/toolchains_llvm++llvm+llvm_toolchain_llvm/lib above the first line allows the program to link and run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions