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:
As a static library
- I created a file
mediapipe/lib/BUILD
with the following content
- I created a file
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 projectThe 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"
- 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 projectDuring 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
bazelisk
instead ofbazel
. Might be useful. – Parole