I am trying to use the Delegate introduced on the following site with TensorFlow Lite. However, when I run make, the following message appears. It seems like there are missing libraries to link, so how can I solve this? I am using v2.16.1 for TensorFlow Lite.
https://mediatek.gitlab.io/genio/doc/tao/npu_acceleration.html
The source code where the problem occurred is stored on GitHub.
/cpp_infer_vab-5000$ mkdir build
debian@vab-5000:~/sandbox/tensorflow_c/peoplenet_onnx_to_tflite
/cpp_infer_vab-5000$ cd build/
debian@vab-5000:~/sandbox/tensorflow_c/peoplenet_onnx_to_tflite
/cpp_infer_vab-5000/build$ cmake ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr (found version "4.6.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/debian/sandbox/tensorflow_c/peoplenet_onnx_to_tflite/cpp_infer_vab-5000/build
debian@vab-5000:~/sandbox/tensorflow_c/peoplenet_onnx_to_tflite
/cpp_infer_vab-5000/build$ make
[ 50%] Building CXX object CMakeFiles/PeopleNetInfer.dir/peoplenet_main.cpp.o
[100%] Linking CXX executable PeopleNetInfer
/usr/bin/ld: CMakeFiles/PeopleNetInfer.dir/peoplenet_main.cpp.o: in function `main':
peoplenet_main.cpp:(.text+0x288): undefined reference to `tflite::delegates::utils::LoadDelegateFromSharedLibrary(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: peoplenet_main.cpp:(.text+0x320): undefined reference to `tflite::delegates::utils::TfLiteSettingsJsonParser::TfLiteSettingsJsonParser()'
/usr/bin/ld: peoplenet_main.cpp:(.text+0x344): undefined reference to `tflite::delegates::utils::TfLiteSettingsJsonParser::Parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/PeopleNetInfer.dir/build.make:157: PeopleNetInfer] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/PeopleNetInfer.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
The cause of this issue was that I did not link libdelegate_loader.so, libtflite_settings_json_parser.so, and libandroid_info.so. However, now I am getting build errors related to flatbuffeers. Do you know any solutions? Thank you.
TensorFlow v2.16.1 is used. The source code is stored below.
# move code
$ cd cpp_infer_vab-5000
# checkout flatbuffer
$ git clone https://github.com/google/flatbuffers.git
$ cd flatbuffers
$ git checkout v23.5.26
$ cd ..
# checkout absl
$ git clone https://github.com/abseil/abseil-cpp.git
$ cd abseil-cpp
$ git checkout 20230802.3
$ cd ..
# build
$ mkdir build
$ cd build
$ cmake ..
$ make
...
[ 61%] Built target absl_statusor
[ 61%] Linking CXX executable PeopleNetInfer
/usr/bin/ld: /home/debian/cross-tf/libtflite_settings_json_parser.so: undefined reference to `flatbuffers::LoadFile(char const*, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
/usr/bin/ld: /home/debian/cross-tf/libtflite_settings_json_parser.so: undefined reference to `flatbuffers::Parser::SetRootType(char const*)'
/usr/bin/ld: /home/debian/cross-tf/libtflite_settings_json_parser.so: undefined reference to `flatbuffers::Parser::Parse(char const*, char const**, char const*)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/PeopleNetInfer.dir/build.make:230: PeopleNetInfer] Error 1
make[1]: *** [CMakeFiles/Makefile2:753: CMakeFiles/PeopleNetInfer.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
This issue was caused by the library not being specified correctly in CMakeLists.txt. I was able to build it after changing it to the following CMakeLists.txt. Sorry for the trouble. Thank you.
cmake_minimum_required(VERSION 2.8)
project(PeopleNetInfer)
# Create Main project
add_executable(PeopleNetInfer
peoplenet_main.cpp
)
# For OpenCV
find_package(OpenCV REQUIRED)
if(OpenCV_FOUND)
target_include_directories(PeopleNetInfer PUBLIC ${OpenCV_INCLUDE_DIRS})
target_link_libraries(PeopleNetInfer ${OpenCV_LIBS})
endif()
### Avseil.io (absl)
add_subdirectory(abseil-cpp)
set(protobuf_ABSL_USED_TARGETS
absl::absl_check
absl::absl_log
absl::algorithm
absl::base
absl::bind_front
absl::bits
absl::btree
absl::cleanup
absl::cord
absl::core_headers
absl::debugging
absl::die_if_null
absl::dynamic_annotations
absl::flags
absl::flat_hash_map
absl::flat_hash_set
absl::function_ref
absl::hash
absl::layout
absl::log_initialize
absl::log_severity
absl::memory
absl::node_hash_map
absl::node_hash_set
absl::optional
absl::span
absl::status
absl::statusor
absl::strings
absl::synchronization
absl::time
absl::type_traits
absl::utility
absl::variant
)
target_link_libraries(PeopleNetInfer ${protobuf_ABSL_USED_TARGETS})
# For Tensorflow Lite
target_link_libraries(PeopleNetInfer /home/debian/cross-tf/libtensorflowlite.so)
target_link_libraries(PeopleNetInfer /home/debian/cross-tf/libdelegate_loader.so)
target_link_libraries(PeopleNetInfer /home/debian/cross-tf/libtflite_settings_json_parser.so)
target_link_libraries(PeopleNetInfer /home/debian/cross-tf/libandroid_info.so)
target_link_libraries(PeopleNetInfer /home/debian/peoplenet_onnx_to_tflite/cpp_infer_vab-5000/flatbuffers/build/libflatbuffers.a)
target_include_directories(PeopleNetInfer PUBLIC /home/debian/tensorflow)
target_include_directories(PeopleNetInfer PUBLIC /home/debian/tensorflow/tensorflow)
target_include_directories(PeopleNetInfer PUBLIC /home/debian/tensorflow/tensorflow/lite)
target_include_directories(PeopleNetInfer PUBLIC /home/debian/peoplenet_onnx_to_tflite/cpp_infer_vab-5000/flatbuffers/include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -lstdc++")
# Copy resouce
file(COPY ${CMAKE_SOURCE_DIR}/resource/ DESTINATION ${PROJECT_BINARY_DIR}/resource/)
add_definitions(-DRESOURCE_DIR="${PROJECT_BINARY_DIR}/resource/")