Hi everyone, hoping to get some help on this, I’ve tried a few things but I can’t work out what is going on.
I have an Android app using Pytorch 1.9.0 routines in native C++. My build.gradle
is essentially set up just like the example NativeApp (android-demo-app/build.gradle at master · pytorch/android-demo-app · GitHub) and it currently builds fine and works as expected using the following in build.gradle
:
dependencies {
implementation 'org.pytorch:pytorch_android:1.9.0'
extractForNativeBuild 'org.pytorch:pytorch_android:1.9.0'
}
Now, I would like to use Pytorch 1.9.0 lite
. So I’ve updated the build.gradle
section above to:
dependencies {
implementation 'org.pytorch:pytorch_android_lite:1.9.0'
extractForNativeBuild 'org.pytorch:pytorch_android_lite:1.9.0'
}
And I’ve changed my native CMakeLists.txt to point the linking to libpytorch_jni_lite.so
(instead of previously libpytorch_jni.so
).
Should be pretty straight forward, but I run into the following linking issues. Note that 2 errors point to methods in torch headers (module.h
and object.h
) and a couple point to the my own file torch_module.cpp
that’s making calls to torch::jit::load
.
In function `torch::jit::Module::forward(std::__ndk1::vector<c10::IValue, std::__ndk1::allocator<c10::IValue> >)': /include/torch/csrc/jit/api/module.h:114: undefined reference to `torch::jit::Method::operator()(std::__ndk1::vector<c10::IValue, std::__ndk1::allocator<c10::IValue> >, std::__ndk1::unordered_map<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, c10::IValue, std::__ndk1::hash<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >, std::__ndk1::equal_to<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >, std::__ndk1::allocator<std::__ndk1::pair<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const, c10::IValue> > > const&)'
In function `torch::jit::Object::get_method(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&) const':
/include/torch/csrc/jit/api/object.h:100: undefined reference to `torch::jit::Object::find_method(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&) const'
In function `TorchModule':
torch_module.cpp:18: undefined reference to `torch::jit::load(std::__ndk1::basic_istream<char, std::__ndk1::char_traits<char> >&, c10::optional<c10::Device>)'
torch_module.cpp:27: undefined reference to `torch::jit::Module::to(c10::Device, bool)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Am I missing something? Thanks heaps for your help.
Aurelien