google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.45k stars 5.15k forks source link

Bazel build failed with error Undefined symbols: _OBJC_CLASS_$_ALAssetsLibrary #4885

Open trunghvbk opened 1 year ago

trunghvbk commented 1 year ago

OS Platform and Distribution

MacOS 13.6

Compiler version

Apple clang version 15.0.0

Programming Language and version

Swift 5

Installed using virtualenv? pip? Conda?(if python)

No response

MediaPipe version

I pull the latest main branch (v10.7 on github version)

Bazel version

bazel 6.3.2-homebrew

XCode and Tulsi versions (if iOS)

XCode 15.0

Android SDK and NDK versions (if android)

No response

Android AAR (if android)

None

OpenCV version (if running on desktop)

No response

Describe the problem

Failed when I run bazel build bazel build //mediapipe/examples/ios/posetrackinggpuswift:PoseTrackingGpuSwiftApp --ios_multi_cpus=arm64 --xcode_version=15.0 BUILD file content:

# Copyright 2020 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load(
    "@build_bazel_rules_apple//apple:ios.bzl",
    "ios_application",
)
load(
    "//mediapipe/examples/ios:bundle_id.bzl",
    "BUNDLE_ID_PREFIX",
    "example_provisioning",
)

licenses(["notice"])

MIN_IOS_VERSION = "13.0"

alias(
    name = "posetrackinggpuswift",
    actual = "PoseTrackingGpuSwiftApp",
)

load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")

load(
    "@rules_xcodeproj//xcodeproj:defs.bzl",
    "top_level_target",
    "xcodeproj",
)

# load("@rules_cc//cc:defs.bzl", "objc_library")

xcodeproj(
    name = "xcodeproj",
    build_mode = "bazel",
    project_name = "PoseTrackingGpuSwiftApp",
    tags = ["manual"],
    top_level_targets = [
        top_level_target(
            ":PoseTrackingGpuSwiftApp",
            target_environments = [
                "device",
                "simulator",
            ],
        ),
    ],
)

ios_application(
    name = "PoseTrackingGpuSwiftApp",
    app_icons = ["AppIcon"],
    bundle_id = "xxx.mediapipe.sample",
    families = [
        "iphone",
        "ipad",
    ],
    infoplists = [
        "Info.plist",
    ],
    minimum_os_version = MIN_IOS_VERSION,
    provisioning_profile = example_provisioning(),
    deps = [
        ":PoseTrackingGpuSwiftAppLibrary",
        "@ios_opencv//:OpencvFramework",
    ],
    visibility = ["//visibility:public"],
)

# objc_library(
#     name = "PoseTrackingGpuAppLibrary",
#     srcs = [
#         "PoseTrackingViewController.mm",
#     ],
#     hdrs = [
#         "PoseTrackingViewController.h",
#     ],
#     copts = ["-std=c++17"],
#     data = [
#         "//mediapipe/graphs/pose_tracking:pose_tracking_gpu.binarypb",
#         "//mediapipe/modules/pose_detection:pose_detection.tflite",
#         "//mediapipe/modules/pose_landmark:pose_landmark_full.tflite",
#     ],
#     deps = [
#         "//mediapipe/examples/ios/common:CommonMediaPipeAppLibrary",
#         "//mediapipe/framework/formats:landmark_cc_proto",
#     ] + select({
#         "//mediapipe:ios_i386": [],
#         "//mediapipe:ios_x86_64": [],
#         "//conditions:default": [
#             "//mediapipe/graphs/pose_tracking:pose_tracking_gpu_deps",
#         ],
#     }),
# )

swift_library(
    name = "PoseTrackingGpuSwiftAppLibrary",
    srcs = glob(["src/*.swift"]),
    # copts = ["-std=c++17"],
    data = [
        "Base.lproj/LaunchScreen.storyboard",
        "Base.lproj/Main.storyboard",
        "//mediapipe/graphs/pose_tracking:pose_tracking_gpu.binarypb",
        "//mediapipe/modules/pose_detection:pose_detection.tflite",
        "//mediapipe/modules/pose_landmark:pose_landmark_full.tflite",
    ],
    visibility = [
        "//mediapipe:__subpackages__",
    ],
    deps = [
        "//mediapipe/objc:mediapipe_framework_ios",
        "//mediapipe/objc:mediapipe_input_sources_ios",
        "//mediapipe/objc:mediapipe_layer_renderer",
        "//third_party/apple_frameworks:AVFoundation",
        "//third_party/apple_frameworks:CoreGraphics",
        "//third_party/apple_frameworks:CoreMedia",
        "//third_party/apple_frameworks:UIKit",
        "//mediapipe/framework/formats:landmark_cc_proto",
    ] 
    + select({
        "//mediapipe:ios_i386": [],
        "//mediapipe:ios_x86_64": [],
        "//conditions:default": [
           "//mediapipe/graphs/pose_tracking:pose_tracking_gpu_deps",
        ],
    }),
)

filegroup(
    name = "AppIcon",
    srcs = glob(["Assets.xcassets/AppIcon.appiconset/*"]),
    visibility = ["//mediapipe:__subpackages__"],
)

Complete Logs

ld: Undefined symbols:
  _OBJC_CLASS_$_ALAssetsLibrary, referenced from:
       in opencv2[arm64][249](cap_ios_video_camera.o)
trunghvbk commented 1 year ago

The Swift project is just a totally new project and I have not added any codes to it. If I remove "//mediapipe/graphs/pose_tracking:pose_tracking_gpu_deps" and "@ios_opencv//:OpencvFramework", in deps, it will build successfully. But I need to use the pose tracking graph to implement the Pose function, so please help. Thanks!

kuaashish commented 1 year ago

Hi @trunghvbk,

Could you please outline the exact steps you are following, referencing the documentation? Additionally, kindly confirm the macOS version you are using—specifying whether it is based on the Silicon chip or Intel. This information will help us reproduce and better understand the issue on our end.

Thank you

trunghvbk commented 1 year ago

Hi @kuaashish The steps I'm following:

My Macbook is Macbook pro 2020 M1.

trunghvbk commented 1 year ago

@kuaashish FYI this is the folder structure image

schmidt-sebastian commented 1 year ago

Can you try building OpenCV from source? You can pass --define=OPENCV=source.

trunghvbk commented 1 year ago

Hi @schmidt-sebastian Thanks for your response I tried using the argument as you said but it appears the ERROR

ERROR: /private/var/tmp/_bazel_admin/dd64d0bbc2d480ced47ba389824ddbde/external/rules_foreign_cc/toolchains/BUILD.bazel:192:11: in ninja_tool rule @rules_foreign_cc//toolchains:ninja_tool: 
Traceback (most recent call last):
    File "/private/var/tmp/_bazel_admin/dd64d0bbc2d480ced47ba389824ddbde/external/rules_foreign_cc/foreign_cc/built_tools/ninja_build.bzl", line 16, column 30, in _ninja_tool_impl
        additional_tools = depset(
Error in depset: at index 0 of transitive, got element of type NoneType, want depset
ERROR: /private/var/tmp/_bazel_admin/dd64d0bbc2d480ced47ba389824ddbde/external/rules_foreign_cc/toolchains/BUILD.bazel:192:11: Analysis of target '@rules_foreign_cc//toolchains:ninja_tool' failed
ERROR: Analysis of target '//mediapipe/examples/ios/posetrackinggpuswift:PoseTrackingGpuSwiftApp' failed; build aborted: 
INFO: Elapsed time: 58.478s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (226 packages loaded, 28508 target\
s configured)