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

Cannot build a target for linux arm64 #13

Closed
seungduk-yanolja opened this issue Mar 11, 2023 · 2 comments
Closed

Cannot build a target for linux arm64 #13

seungduk-yanolja opened this issue Mar 11, 2023 · 2 comments

Comments

@seungduk-yanolja
Copy link

seungduk-yanolja commented Mar 11, 2023

Hello there,

First of all, thanks for the great work.
Using the following rule, I am trying to integrate a CPP library into a Go package.

# This rule is defined for each architecture in each directory.
cc_import(
    name = "banana_lib",
    static_library = "libbanana_static.a",
)

go_library(
    name = "banana",
    srcs = glob(["include/**/*.h"]) + [
        "cfunc.go",
        "banana.go",
    ],  # keep
    cdeps = select({
        "@io_bazel_rules_go//go/platform:linux_arm64": [
            "//test/banana/linux_arm64:banana_lib",
        ],
        "@io_bazel_rules_go//go/platform:linux_amd64": [
            "//test/banana/linux_amd64:banana_lib",
        ],
        "@io_bazel_rules_go//go/platform:darwin_amd64": [
            "//test/banana/darwin_x86_64:banana_lib",
        ],
        "@io_bazel_rules_go//go/platform:darwin_arm64": [
            "//test/banana/darwin_arm64:banana_lib",
        ],
        "//conditions:default": [],
    }),
    cgo = True,
    clinkopts = ["-lpthread -lstdc++"],
    data = [":banana_dict"],
    importpath = "seungduk.kim/test/banana",
)

It requires a toolchain, so I imported bazel-zig-cc in WORKSPACE.

BAZEL_ZIG_CC_VERSION = "v1.0.1"

http_archive(
    name = "bazel-zig-cc",
    sha256 = "e9f82bfb74b3df5ca0e67f4d4989e7f1f7ce3386c295fd7fda881ab91f83e509",
    strip_prefix = "bazel-zig-cc-{}".format(BAZEL_ZIG_CC_VERSION),
    urls = ["https://git.sr.ht/~motiejus/bazel-zig-cc/archive/{}.tar.gz".format(BAZEL_ZIG_CC_VERSION)],
)

load("@bazel-zig-cc//toolchain:defs.bzl", zig_toolchains = "toolchains")

zig_toolchains()

And I ran the following command.

 bazel build --platforms @zig_sdk//platform:linux_arm64 --extra_toolchains @zig_sdk//toolchain:linux_arm64_gnu.2.28  --incompatible_enable_cc_toolchain_resolution  //test/banana

Running the command above resulted the following.

ld.lld: error: undefined symbol: std::string::compare(char const*) const
>>> referenced by ArchUtils.cpp
>>>               ArchUtils.cpp.o:(parseArchType(char const*)) in archive experimental/seungduk.kim/test/banana/linux_arm64/libbanana_static.a

ld.lld: error: undefined symbol: std::_Rb_tree_increment(std::_Rb_tree_node_base const*)
>>> referenced by ModelDetector.cpp
>>>               ModelDetector.cpp.o:(banana::ModelDetector::saveModel(std::string const&) const) in archive experimental/seungduk.kim/test/banana/linux_arm64/libbanana_static.a
>>> referenced by ModelDetector.cpp
>>>               ModelDetector.cpp.o:(banana::ModelDetector::saveModel(std::string const&) const) in archive experimental/seungduk.kim/test/banana/linux_arm64/libbanana_static.a
>>> referenced by ModelDetector.cpp
>>>               ModelDetector.cpp.o:(banana::ModelDetector::saveModel(std::string const&) const) in archive experimental/seungduk.kim/test/banana/linux_arm64/libbanana_static.a
>>> referenced 8 more times

ld.lld: error: undefined symbol: std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)
>>> referenced by ModelDetector.cpp
>>>               ModelDetector.cpp.o:(banana::ModelDetector::countNgram(banana::ModelDetector::Counter&, std::function<std::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t>> ()> const&, unsigned long, unsigned long) const) in archive experimental/seungduk.kim/test/banana/linux_arm64/libbanana_static.a
>>> referenced by ModelDetector.cpp
>>>               ModelDetector.cpp.o:(banana::ModelDetector::countNgram(banana::ModelDetector::Counter&, std::function<std::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t>> ()> const&, unsigned long, unsigned long) const) in archive experimental/seungduk.kim/test/banana/linux_arm64/libbanana_static.a
compilepkg: error running subcommand external/zig_sdk/tools/aarch64-linux-gnu.2.28/c++: exit status 1
Target //experimental/seungduk.kim/test:test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 32.203s, Critical Path: 31.75s
INFO: 5 processes: 2 internal, 3 darwin-sandbox.
FAILED: Build did NOT complete successfully

I also tried @zig_sdk//toolchain:linux_arm64_musl but nothing worked. I am using a darwin_arm64 machine and every targets of darwin (darwin_arm64, darwin_amd64) works well.
The error messages seem like all standard libraries failed to be linked. Any thoughts?

Thank you!

@motiejus
Copy link
Collaborator

Here is the crux of the problem: ziglang/zig#9832 (comment)

TLDR: compile your dependencies with zig c++ too.

@seungduk-yanolja
Copy link
Author

No easy job there... Thanks a lot!

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

2 participants