Linker errors when compiling code
I have been trying to test out my build of the Arm NN library by loading in a sample tensorflow model and creating the delegate and interpreter. I have not included a lot of code because I am simply trying to get the basics working first.
I keep getting linker errors when I compile and am very lost on how to resolve them.
Below is my code
`
#include
#include "armnn/delegate/include/DelegateOptions.hpp" #include "armnn/BackendOptions.hpp" #include "armnn/ArmNN.hpp"
#include "armnn/delegate/include/armnn_delegate.hpp" #include "armnn/delegate/src/test/TestUtils.hpp" #include "armnn/third-party/doctest/doctest.h"
#include "tensorflow/lite/interpreter.h" #include "tensorflow/lite/interpreter_builder.h" #include "tensorflow/lite/kernels/register.h" #include "tensorflow/lite/model.h" #include "tensorflow/lite/tools/gen_op_registration.h"
int main() {
std::unique_ptr<tflite::FlatBufferModel> tfLiteModel =
tflite::FlatBufferModel::BuildFromFile("/home/avirn/tflite_test/detect.tflite");
std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
// Create TfLite Interpreter
std::unique_ptr<tflite::Interpreter> armnnDelegateInterpreter;
tflite::InterpreterBuilder(*tfLiteModel.get(), ::tflite::ops::builtin::BuiltinOpResolver())
(&armnnDelegateInterpreter);
// Create the Arm NN Delegate
armnnDelegate::DelegateOptions delegateOptions(backends);
std::unique_ptr<TfLiteDelegate, decltype(&armnnDelegate::TfLiteArmnnDelegateDelete)>
theArmnnDelegate(armnnDelegate::TfLiteArmnnDelegateCreate(delegateOptions),
armnnDelegate::TfLiteArmnnDelegateDelete);
// Instruct the Interpreter to use the armnnDelegate
armnnDelegateInterpreter->ModifyGraphWithDelegate(theArmnnDelegate.get());
return 0;
}`
and the error I'm currently getting is
/usr/bin/ld: tflite_detect.o: in function main':
tflite_detect.cpp:(.text+0x1cd): undefined reference to armnnDelegate::DelegateOptions::DelegateOptions(std::vector<armnn::BackendId, std::allocator<armnn::BackendId> > const&, std::vector<armnn::BackendOptions, std::allocator<armnn::BackendOptions> > const&, armnn::Optional<armnn::LogSeverity>)' /usr/bin/ld: tflite_detect.cpp:(.text+0x1f2): undefined reference to armnnDelegate::TfLiteArmnnDelegateDelete(TfLiteDelegate*)'
/usr/bin/ld: tflite_detect.cpp:(.text+0x221): undefined reference to armnnDelegate::TfLiteArmnnDelegateCreate(armnnDelegate::DelegateOptions)' /usr/bin/ld: tflite_detect.o: in function __static_initialization_and_destruction_0(int, int)':
tflite_detect.cpp:(.text+0x4ee): undefined reference to doctest::detail::TestSuite::operator*(char const*)' /usr/bin/ld: tflite_detect.cpp:(.text+0x4f6): undefined reference to doctest::detail::setTestSuite(doctest::detail::TestSuite const&)'
/usr/bin/ld: tflite_detect.o: in function armnn::Exception::~Exception()': tflite_detect.cpp:(.text._ZN5armnn9ExceptionD2Ev[_ZN5armnn9ExceptionD5Ev]+0x13): undefined reference to vtable for armnn::Exception'
/usr/bin/ld: tflite_detect.o: in function armnn::BadOptionalAccessException::Exception(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': tflite_detect.cpp:(.text._ZN5armnn26BadOptionalAccessExceptionCI2NS_9ExceptionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN5armnn26BadOptionalAccessExceptionCI5NS_9ExceptionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x23): undefined reference to armnn::Exception::Exception(std::__cxx11::basic_string<char, std::char_traitsarmnn::Exception::what() const' /usr/bin/ld: tflite_detect.o:(.data.rel.ro._ZTIN5armnn26BadOptionalAccessExceptionE[_ZTIN5armnn26BadOptionalAccessExceptionE]+0x10): undefined reference to typeinfo for armnn::Exception'
collect2: error: ld returned 1 exit status
make: *** [Makefile:51: app] Error 1`
My build passed all unit and benchmark tests and I have included these libraries:
-l tensorflow-lite \ -l fft2d_fftsg \ -l fft2d_fftsg2d \ -l flatbuffers \ -l ruy \ -l farmhash \ -l pthread \ -l dl \
Hi @avirn ,
Can you provide more info on the issue? What ArmNN version and what TfLite version are you using? Can you share the cmake command used to build? What device and os are you using?
Regards, Ryan
Using ArmNN v22.05.01, Tensorflow v2.5.0.
I used
cmake .. -DARMCOMPUTE_ROOT=$BASEDIR/ComputeLibrary -DARMCOMPUTENEON=0 -DBUILD_UNIT_TESTS=1
to build ArmNN
and
cmake .. -DCMAKE_BUILD_TYPE=release DTENSORFLOW_ROOT=$BASEDIR/tensorflow \ DTFLITE_LIB_ROOT=$BASEDIR/tensorflow/build \ DFLATBUFFERS_ROOT=$BASEDIR/flatbuffers-1.12.0/install \ DArmnn_DIR=$BASEDIR/armnn/build \ DARMNN_SOURCE_DIR=$BASEDIR/armnn
to build the stand-alone delegate
os: Ubuntu 20.04.4 LTS
x86_64 architecture (is that what you mean by device?)
Hi @avirn ,
I built the delegate and armnn v22.05.1 using the cmake commands above, and I was able to compile this:
#include "armnn/delegate/include/DelegateOptions.hpp"
#include "armnn/BackendOptions.hpp"
#include "armnn/ArmNN.hpp"
#include "armnn/Logging.hpp"
#include "armnn/delegate/include/armnn_delegate.hpp"
#include <tensorflow/lite/builtin_ops.h>
#include <tensorflow/lite/c/builtin_op_data.h>
#include <tensorflow/lite/c/common.h>
#include <tensorflow/lite/optional_debug_tools.h>
#include <tensorflow/lite/kernels/builtin_op_kernels.h>
#include <tensorflow/lite/interpreter.h>
#include <tensorflow/lite/kernels/register.h>
int main() {
std::unique_ptr<tflite::FlatBufferModel> tfLiteModel =
::tflite::FlatBufferModel::BuildFromFile("/dev/devenv/models/fsrcnn_fp32.tflite");
std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
// Create TfLite Interpreter
auto tfLiteInterpreter = std::make_unique<tflite::Interpreter>();
tflite::ops::builtin::BuiltinOpResolver resolver;
tflite::InterpreterBuilder builder(*tfLiteModel, resolver);
builder(&tfLiteInterpreter);
tfLiteInterpreter->AllocateTensors();
// Create the Arm NN Delegate
armnnDelegate::DelegateOptions delegateOptions(backends);
std::unique_ptr<TfLiteDelegate, decltype(&armnnDelegate::TfLiteArmnnDelegateDelete)>
theArmnnDelegate(armnnDelegate::TfLiteArmnnDelegateCreate(delegateOptions),
armnnDelegate::TfLiteArmnnDelegateDelete);
// Instruct the Interpreter to use the armnnDelegate
tfLiteInterpreter->ModifyGraphWithDelegate(std::move(theArmnnDelegate));
return 0;
}
with tflite 2.5 on ubuntu 20.04 x86 using the following command:
gcc -g -o tflite_detect tflite_detect.cpp -L$HOME/dev/devenv/ArmNNLibs/ -L/$HOME/dev/devenv/DelegateLibs/ -L$HOME/dev/devenv/TfLiteBuild/x86_64/ -L$HOME/dev/devenv/TfLiteBuild/x86_64/_deps/ruy-build/ -L$HOME/dev/devenv/TfLiteBuild/x86_64/_deps/fft2d-build -L$HOME/dev/devenv/x86_64/flatbuffers/lib/ -L$HOME/dev/devenv/TfLiteBuild/x86_64/_deps/farmhash-build/ -larmnn -larmnnDelegate -ltensorflow-lite -lruy -ldl -pthread -lrt -lfft2d_fftsg -lfft2d_fftsg2d -lfarmhash -lflatbuffers -lstdc++ -lm -I$HOME/dev/devenv/armnn/include/ -I$HOME/dev/devenv/armnn/profiling/ -I$HOME/dev/devenv/tensorflow/ -I$HOME/dev/devenv/armnn/third-party/ -I$HOME/dev/devenv/x86_64/flatbuffers/include/
~/dev/devenv$ ./tflite_detect
INFO: TfLiteArmnnDelegate: Created TfLite ArmNN delegate.
Hopefully that helps, let me know if there are any more issues! The doctest errors come from including the test utils header, but none of the test utils are actually used in the file. I'm not overly sure where the other issues came from, as I didn't encounter them.
Thank you so much! I was able to compile and run as well.
I have one last question if I was to use the test utils what else do I need to include? I included the doctest but still getting linker errors related to doctest.
That's great!
As far as I'm aware, adding this "-larmnnTestUtils" to your compilation should suffice. It was just missing the compiled symbols I think.