Skip to content

Presence of gcc-cross tools breaks cross-compilation with zig c++ #10777

Closed

Description

@PiotrSikora

Zig Version

0.10.0-dev.528+f95fcb2b1

Steps to Reproduce

$ cat hello.cpp 
#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Install gcc-cross tools for aarch64 (this breaks the build)

$ sudo apt install -y g++-aarch64-linux-gnu

Expected Behavior

$ rm -rf ~/.cache/zig && zig c++ -v -target aarch64-linux-musl hello.cpp && file ./a.out
clang version 13.0.0 (https://github.com/ziglang/zig-bootstrap.git 4ed79aefb7a58a6d642f47a81e1ef04fd164042b)                                                                                                                                              
Target: aarch64-unknown-linux-musl                                                                                                                                                                                                                        
Thread model: posix                                                                                                                                                                                                                                       
InstalledDir: /usr/lib/llvm-13/bin                                                                                                                                                                                                                        
[...]
a.out: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, stripped

Actual Behavior

$ rm -rf ~/.cache/zig && zig c++ -v -target aarch64-linux-musl hello.cpp && file ./a.out
clang version 13.0.0 (https://github.com/ziglang/zig-bootstrap.git 4ed79aefb7a58a6d642f47a81e1ef04fd164042b)
Target: aarch64-unknown-linux-musl
Thread model: posix
InstalledDir: /usr/lib/llvm-13/bin
Found candidate GCC installation: /usr/lib/gcc-cross/aarch64-linux-gnu/11
Selected GCC installation: /usr/lib/gcc-cross/aarch64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
[...]
ld.lld: error: undefined symbol: __aarch64_ldadd8_acq_rel
>>> referenced by cxa_exception.cpp
>>>               /root/.cache/zig/o/6eee571a85eafaabee575c7127a903b0/cxa_exception.o:(__cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)) in archive /root/.cache/zig/o/530ffec9b20ea4d9d93d1f9e2815f09f/libc++abi.a
>>> referenced by cxa_exception.cpp
>>>               /root/.cache/zig/o/6eee571a85eafaabee575c7127a903b0/cxa_exception.o:(__cxa_end_catch) in archive /root/.cache/zig/o/530ffec9b20ea4d9d93d1f9e2815f09f/libc++abi.a
>>> referenced by cxa_exception.cpp
>>>               /root/.cache/zig/o/6eee571a85eafaabee575c7127a903b0/cxa_exception.o:(__cxa_decrement_exception_refcount) in archive /root/.cache/zig/o/530ffec9b20ea4d9d93d1f9e2815f09f/libc++abi.a
>>> referenced 8 more times

ld.lld: error: undefined symbol: __aarch64_swp8_acq_rel
>>> referenced by cxa_handlers.cpp
>>>               /root/.cache/zig/o/a71f0a776c9aeea06560b2500ffa1828/cxa_handlers.o:(std::set_new_handler(void (*)())) in archive /root/.cache/zig/o/530ffec9b20ea4d9d93d1f9e2815f09f/libc++abi.a
>>> referenced by cxa_default_handlers.cpp
>>>               /root/.cache/zig/o/66c5fcf0a2b0aad28259afe5c3cb936c/cxa_default_handlers.o:(std::set_unexpected(void (*)())) in archive /root/.cache/zig/o/530ffec9b20ea4d9d93d1f9e2815f09f/libc++abi.a
>>> referenced by cxa_default_handlers.cpp
>>>               /root/.cache/zig/o/66c5fcf0a2b0aad28259afe5c3cb936c/cxa_default_handlers.o:(std::set_terminate(void (*)())) in archive /root/.cache/zig/o/530ffec9b20ea4d9d93d1f9e2815f09f/libc++abi.a

ld.lld: error: undefined symbol: __aarch64_ldadd4_acq_rel
>>> referenced by ios.cpp
>>>               /root/.cache/zig/o/ddb6aef311b844fc43c6171812f69b6a/ios.o:(std::__1::ios_base::xalloc()) in archive /root/.cache/zig/o/8db9de3dbc883d88b6b664ef2d07e036/libc++.a
>>> referenced by stdlib_stdexcept.cpp
>>>               /root/.cache/zig/o/a738e730253ecc25f615ac90cf6b3870/stdlib_stdexcept.o:(std::logic_error::~logic_error()) in archive /root/.cache/zig/o/530ffec9b20ea4d9d93d1f9e2815f09f/libc++abi.a
>>> referenced by stdlib_stdexcept.cpp
>>>               /root/.cache/zig/o/a738e730253ecc25f615ac90cf6b3870/stdlib_stdexcept.o:(std::logic_error::~logic_error()) in archive /root/.cache/zig/o/530ffec9b20ea4d9d93d1f9e2815f09f/libc++abi.a
>>> referenced 16 more times

ld.lld: error: undefined symbol: __aarch64_ldadd8_relax
>>> referenced by memory.cpp
>>>               /root/.cache/zig/o/0e516735b66b21afefaf4dc1a71d91bf/memory.o:(std::__1::__shared_count::__add_shared()) in archive /root/.cache/zig/o/8db9de3dbc883d88b6b664ef2d07e036/libc++.a
>>> referenced by memory.cpp
>>>               /root/.cache/zig/o/0e516735b66b21afefaf4dc1a71d91bf/memory.o:(std::__1::__shared_weak_count::__add_shared()) in archive /root/.cache/zig/o/8db9de3dbc883d88b6b664ef2d07e036/libc++.a
>>> referenced by memory.cpp
>>>               /root/.cache/zig/o/0e516735b66b21afefaf4dc1a71d91bf/memory.o:(std::__1::__shared_weak_count::__add_weak()) in archive /root/.cache/zig/o/8db9de3dbc883d88b6b664ef2d07e036/libc++.a

ld.lld: error: undefined symbol: __aarch64_cas8_acq_rel
>>> referenced by memory.cpp
>>>               /root/.cache/zig/o/0e516735b66b21afefaf4dc1a71d91bf/memory.o:(std::__1::__shared_weak_count::lock()) in archive /root/.cache/zig/o/8db9de3dbc883d88b6b664ef2d07e036/libc++.a

Activity

  1. added
    bug
    on Feb 3, 2022
  2. added this to the 0.11.0 milestone on Aug 19, 2022
  3. modified the milestones: 0.11.0, 0.12.0 on Jun 19, 2023
  4. added
    zig cc
    on Aug 13, 2024
  5. modified the milestones: 0.14.0, unplanned on Aug 13, 2024
  6. polarathene commented on Oct 19, 2025

    @polarathene

    This issue can be closed it was resolved in Zig 0.11.0:

    # Reproduction environment:
    $ docker run --rm -it --workdir /example ubuntu:24.04 bash
    $ apt-get -qq update && apt-get install -qq curl file g++-aarch64-linux-gnu
    $ curl -LsSf https://astral.sh/uv/install.sh | sh
    $ source $HOME/.local/bin/env && uv python install
    
    # Create the source file:
    $ cat <<HEREDOC > main.cpp
    #include <iostream>
    
    int main() {
        std::cout << "Hello, World!" << std::endl;
        return 0;
    }
    HEREDOC
    
    # Build with Zig (successful from `0.11.0` onwards, `0.10.0` will reproduce reported error):
    $ uvx --from ziglang==0.15.1 python -m ziglang c++ -target aarch64-linux-musl main.cpp
    
    $ file ./a.out
    ./a.out: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, with debug_info, not stripped
  7. modified the milestones: unplanned, 0.16.0 on Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugos-linuxzig cc

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions