MediaPipe library build on macOS
Asked Answered
S

1

6

I'm trying to build MediaPipe as library on macOS to be able to use it in a desktop project with CMake, but I'm running into issues. I'm trying to convert the Hello World example to a library, using hello_world.cc with MediaPipe as an external lib. I tried static and dynamic library build as well, but I have encountered issues with both of them.

At the moment I'm stuck and any help would be greatly appreciated.

The steps of building the libraries and the received errors are below:

  1. As a static library

    • I created a file mediapipe/lib/BUILD with the following content
apple_static_library(
    name = "mediapipe",
    minimum_os_version = "10.14",
    platform_type = "macos",
    deps = [
        "//mediapipe/calculators/core:pass_through_calculator",
        "//mediapipe/framework:calculator_graph",
        "//mediapipe/framework/port:logging",
        "//mediapipe/framework/port:parse_text_proto",
        "//mediapipe/framework/port:status",
    ],
)
  • Built the lib
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/lib:mediapipe
  • Copied bazel-out/apl-darwin_x86_64-opt/bin/mediapipe/lib/mediapipe_lipo.a to my desktop project

  • The project has been built without errors, but it gives the following errors when ran:

Not found: ValidatedGraphConfig Initialization failed.
No registered object with name: PassThroughCalculator; Unable to find Calculator "PassThroughCalculator"
No registered object with name: PassThroughCalculator; Unable to find Calculator "PassThroughCalculator"
  1. As a dynamic library

I read some github issues that building an iOS dynamic library does not exhibit the problems above.

  • Bazel build file mediapipe/dylib/BUILD with the following content
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_dylib")

macos_dylib(
    name = "mediapipe",
    minimum_os_version = "10.15",
    deps = [
        "//mediapipe/framework:calculator_framework",
        "//mediapipe/framework/port:commandlineflags",
        "//mediapipe/framework/port:file_helpers",
        "//mediapipe/framework/port:map_util",
        "//mediapipe/framework/port:parse_text_proto",
        "//mediapipe/framework/port:ret_check",
        "//mediapipe/framework/port:status",
        "//mediapipe/framework/port:statusor",
        "@com_google_absl//absl/strings",
        #"//mediapipe/graphs/hand_tracking:desktop_tflite_calculators",
        "//mediapipe/calculators/core:pass_through_calculator",
    ],
)
  • Built the dylib
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/dylib:mediapipe
  • Fixed the dylib id
chmod 755 mediapipe.dylib
install_name_tool -id mediapipe.dylib mediapipe.dylib
  • Copied bazel-bin/mediapipe/dylib/mediapipe.dylib to my project

  • During build I get linking errors:

Undefined symbols for architecture x86_64:
  "mediapipe::CalculatorGraph::Initialize(mediapipe::CalculatorGraphConfig const&)", referenced from:
      mediapipe::PrintHelloWorld() in MediaPipeApp.cpp.o
      MediaPipeApp::setup() in MediaPipeApp.cpp.o
  "mediapipe::CalculatorGraph::WaitUntilDone()", referenced from:
      mediapipe::PrintHelloWorld() in MediaPipeApp.cpp.o
  "mediapipe::CalculatorGraph::CloseInputStream(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      mediapipe::PrintHelloWorld() in MediaPipeApp.cpp.o
  "mediapipe::CalculatorGraph::AddOutputStreamPoller(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      mediapipe::PrintHelloWorld() in MediaPipeApp.cpp.o
  "mediapipe::CalculatorGraph::AddPacketToInputStream(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, mediapipe::Packet&&)", referenced from:
      mediapipe::PrintHelloWorld() in MediaPipeApp.cpp.o
  "mediapipe::CalculatorGraph::StartRun(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, mediapipe::Packet, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, mediapipe::Packet> > > const&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, mediapipe::Packet, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, mediapipe::Packet> > > const&)", referenced from:
      mediapipe::PrintHelloWorld() in MediaPipeApp.cpp.o
  "mediapipe::CalculatorGraph::CalculatorGraph()", referenced from:
      mediapipe::PrintHelloWorld() in MediaPipeApp.cpp.o
      MediaPipeApp::setup() in MediaPipeApp.cpp.o
  "mediapipe::CalculatorGraph::~CalculatorGraph()", referenced from:
      mediapipe::PrintHelloWorld() in MediaPipeApp.cpp.o
      MediaPipeApp::setup() in MediaPipeApp.cpp.o
  "mediapipe::internal::OutputStreamPollerImpl::Next(mediapipe::Packet*)", referenced from:
      mediapipe::PrintHelloWorld() in MediaPipeApp.cpp.o
ld: symbol(s) not found for architecture x86_64
Swag answered 11/2, 2020 at 13:19 Comment(2)
Hi @Gabor, were you able to find a solution to this? I am working on something similar right now. I was able to figure out how to build an iOS framework using ios_framework, but I need to do mac OS as well.Figment
In here they mention to use bazelisk instead of bazel. Might be useful.Parole
C
0

Try using xcode 11 beta 4 or higher. Apple moved swift libraries into "swift-5.0" directory, hence tulsi fails to build. A workaround would be soft-linking the libraries from "swift-5.0" to the "swift" directory and then re-run the build process. refer to https://forums.developer.apple.com/thread/120074.

Consequential answered 19/12, 2022 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.