-
Notifications
You must be signed in to change notification settings - Fork 75k
Description
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS Mojave (10.14)
- TensorFlow installed from (source or binary): source
- TensorFlow version: r2.2
- Python version: 3.7
- Installed using virtualenv? pip? conda?: pip
- Bazel version (if compiling from source): 3.1.0
- GCC/Compiler version (if compiling from source): Apple clang version 11.0.0 (clang-1100.0.33.17)
- CUDA/cuDNN version: -
- GPU model and memory: -
I am trying to develop a C++ library on macOS and ubuntu to use in Android and iOS. Therefore, I am trying to build TFLite C++ shared library to link it my own C++ shared library using CMake. I have tried to build that using command bazel build -c opt //tensorflow/lite:tensorflowlite and got libtensorflowlite.dylib file as bazel-output. However CMake fails to link it and gives the following error:
Undefined symbols for architecture x86_64:
"tflite::FlatBufferModel::BuildFromFile(char const*, tflite::ErrorReporter*)", referenced from:
MyClass::MyClass(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int) in my_class.cpp.o
"tflite::FlatBufferModel::~FlatBufferModel()", referenced from:
std::__1::default_delete<tflite::FlatBufferModel>::operator()(tflite::FlatBufferModel*) const in my_class.cpp.o
"tflite::DefaultErrorReporter()", referenced from:
MyClass::MyClass(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int) in my_class.cpp.o
"tflite::ops::builtin::BuiltinOpResolver::BuiltinOpResolver()", referenced from:
MyClass::MyClass(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int) in my_class.cpp.o
"tflite::impl::Interpreter::AllocateTensors()", referenced from:
MyClass::MyClass(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int) in my_class.cpp.o
MyClass::run_model(std::__1::vector<std::__1::vector<float, std::__1::allocator<float> >, std::__1::allocator<std::__1::vector<float, std::__1::allocator<float> > > > const&) in my_class.cpp.o
"tflite::impl::Interpreter::ResizeInputTensor(int, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
MyClass::run_model(std::__1::vector<std::__1::vector<float, std::__1::allocator<float> >, std::__1::allocator<std::__1::vector<float, std::__1::allocator<float> > > > const&) in my_class.cpp.o
"tflite::impl::Interpreter::Invoke()", referenced from:
MyClass::run_model(std::__1::vector<std::__1::vector<float, std::__1::allocator<float> >, std::__1::allocator<std::__1::vector<float, std::__1::allocator<float> > > > const&) in my_class.cpp.o
"tflite::impl::Interpreter::~Interpreter()", referenced from:
std::__1::default_delete<tflite::impl::Interpreter>::operator()(tflite::impl::Interpreter*) const in my_class.cpp.o
"tflite::impl::InterpreterBuilder::InterpreterBuilder(tflite::FlatBufferModel const&, tflite::OpResolver const&)", referenced from:
MyClass::MyClass(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int) in my_class.cpp.o
"tflite::impl::InterpreterBuilder::~InterpreterBuilder()", referenced from:
MyClass::MyClass(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int) in my_class.cpp.o
"tflite::impl::InterpreterBuilder::operator()(std::__1::unique_ptr<tflite::impl::Interpreter, std::__1::default_delete<tflite::impl::Interpreter> >*)", referenced from:
MyClass::MyClass(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int) in my_class.cpp.o
"vtable for tflite::MutableOpResolver", referenced from:
tflite::MutableOpResolver::~MutableOpResolver() in my_class.cpp.o
But, If I try to link shared tflite library(libtensorflowlite.dylib) with my static library, it builds without error.
I am fairly new to bazel and CMake, however I thought it is caused by building the libtensorflowlite.dylib with missing x86_64 architecture and tried below commands and got following errors.:
bazel build -c opt --config=ios_fat //tensorflow/lite:tensorflowlite
ERROR: /Users/username/tensorflow/tensorflow/lite/kernels/internal/BUILD:687:1: C++ compilation of rule '//tensorflow/lite/kernels/internal:kernel_utils' failed (Exit 1)
clang: error: invalid version number in '-mmacosx-version-min=13.2'
and
bazel build -c opt --cpu=x86_64 //tensorflow/lite:tensorflowlite
ERROR: /private/var/tmp/_bazel_username/ec3ee607500668f8e05b1977bf58c2f5/external/local_config_cc/BUILD:41:1: in cc_toolchain_suite rule @local_config_cc//:toolchain: cc_toolchain_suite '@local_config_cc//:toolchain' does not contain a toolchain for cpu 'x86_64'
ERROR: Analysis of target '//tensorflow/lite:tensorflowlite' failed; build aborted: Analysis of target '@local_config_cc//:toolchain' failed
Finally, I thought it is related to #36178 , #39876 and #35386, but couldn't resolve it.