1

I think the problem is I'm not including the shared library in the right away, but I'm not sure.

The error I get is

error: undefined reference to 'tflite::InterpreterBuilder::operator()(std::__ndk1::unique_ptr<tflite::Interpreter, std::__ndk1::default_delete<tflite::Interpreter> >*)

Which points at the last line of:

std::unique_ptr<tflite::FlatBufferModel> model = tflite::FlatBufferModel::BuildFromFile(casemodel_path.c_str());
tflite::ops::builtin::BuiltinOpResolver resolver;
tflite::InterpreterBuilder builder(*model.get(), resolver);
std::unique_ptr<tflite::Interpreter> interpreter;
builder(&interpreter);

I took this from here, as the documentation seems to be out of date.

I compiled tensorflow from source using NDK16b. I followed this to compile it.

The relevant portion of my cmake file looks like:

[...]
# Flatbuffer
set(FLATB_DIR <path-to>/git/flatbuffers)
include_directories(${FLATB_DIR}/include)
include_directories(${FLATB_DIR}/grpc)

file(GLOB flatb_src "${FLATB_DIR}/src/*.cpp")
add_library(flatbuffer ${flatb_src})

add_library(libtensorflowlite SHARED IMPORTED)
set_target_properties(libtensorflowlite PROPERTIES IMPORTED_LOCATION
        <path-to>/app/src/main/jniLibs/armeabi-v7a/libtensorflowlite.so)


include_directories(<path-to>/git/tensorflow-android)
[...]
target_link_libraries(flatbuffer libtensorflowlite <tons-of-other-libraries>)

As I mentioned already I think the problem is I'm not including the shared library in the right way. All I've done is created the folder(s) jniLibs/armeabi-v7a/ under src/main, where I put the libtensorflowlite.so. Googling around that seems to be one way to do it? I've tried some other ways (with sourceSets and implementation fileTree but nothing worked).

I've got some other precompiled libraries that I'm using just fine, but they are static (in target_link_libraries I point directly to their path). Is it a problem mixing static/shared libraries like that?

edit: Following this, I also tried using ndk15c and editing ANDROID_NDK_API_LEVEL, but that did not help.

Nimitz14
  • 2,138
  • 5
  • 23
  • 39

0 Answers0