Skip to content

windows 10, ld.lld: unknown -z value: separate-code; error: cannot open crtbegin_so.o; error: cannot open crtend_so.o #101

@wxfred

Description

@wxfred

$env:ANDROID_NDK_HOME="C:/Users/xxx/AppData/Local/Android/Sdk/ndk/21.0.6113669"
bazel build //:jni --cpu=arm64-v8a --crosstool_top=@androidndk//:toolchain

INFO: Analyzed target //:jni (39 packages loaded, 4184 targets configured).
INFO: Found 1 target...
ERROR: C:/xxx/bazelndktest-pure/BUILD:9:11: Linking libjni.so failed: (Exit 1): clang.exe failed: error executing command (from target //:jni) external\androidndk\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe @bazel-out/arm64-v8a-fastbuild/bin/libjni.so-2.params
ld.lld: error: unknown -z value: separate-code
ld.lld: error: cannot open crtbegin_so.o: No such file or directory
ld.lld: error: cannot open crtend_so.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Target //:jni failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 5.097s, Critical Path: 0.40s
INFO: 5 processes: 3 internal, 2 local.
FAILED: Build did NOT complete successfully

all my files:
BUILD

platform(
    name = "arm64-v8a",
    constraint_values = [
        "@platforms//cpu:arm64",
        "@platforms//os:android",
    ],
)

cc_library(
    name = "jni",
    srcs = ["jni.cc"],
)

jni.cc

#include <jni.h>
#include <stdio.h>

extern "C" JNIEXPORT int JNICALL
Java_com_app_Jni_getValue(JNIEnv *env, jclass clazz) {
    printf("hello world!");
    return 1;
}

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "rules_cc",
    sha256 = "abc605dd850f813bb37004b77db20106a19311a96b2da1c92b789da529d28fe1",
    strip_prefix = "rules_cc-0.0.17",
    urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz"],
)

http_archive(
    name = "rules_android_ndk",
    sha256 = "89bf5012567a5bade4c78eac5ac56c336695c3bfd281a9b0894ff6605328d2d5",
    strip_prefix = "rules_android_ndk-0.1.3",
    url = "https://github.com/bazelbuild/rules_android_ndk/releases/download/v0.1.3/rules_android_ndk-v0.1.3.tar.gz",
)
load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")

android_ndk_repository(name = "androidndk")

register_toolchains("@androidndk//:all")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions