pytorch-android-cpp-demo
pytorch-android-cpp-demo copied to clipboard
facing build issue with build_android.sh
I am using android ndk-19 version for building the demo.
I am getting the following error while building for arm64-v8a:
-f may not be used without -shared
When I add the -shared flag in build_android/CMakeFiles/Predictor.dir/link.txt file, it gives the following new issue:
CMakeFiles/Predictor.dir/predictor.cpp.o: In function `(anonymous namespace)::loadModel(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)':
/home/anussark/pytorch-android-cpp-demo/predictor.cpp:26: undefined reference to `torch::jit::load(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, c10::optional<c10::Device>)'
CMakeFiles/Predictor.dir/predictor.cpp.o: In function `torch::jit::Module::eval()':
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/module.h:184: undefined reference to `torch::jit::Module::train(bool)'
CMakeFiles/Predictor.dir/predictor.cpp.o: In function `~GraphOptimizerEnabledGuard':
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/runtime/graph_executor.h:123: undefined reference to `torch::jit::setGraphExecutorOptimize(bool)'
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/runtime/graph_executor.h:123: undefined reference to `torch::jit::setGraphExecutorOptimize(bool)'
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/runtime/graph_executor.h:123: undefined reference to `torch::jit::setGraphExecutorOptimize(bool)'
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/runtime/graph_executor.h:123: undefined reference to `torch::jit::setGraphExecutorOptimize(bool)'
CMakeFiles/Predictor.dir/predictor.cpp.o: In function `GraphOptimizerEnabledGuard':
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/runtime/graph_executor.h:118: undefined reference to `torch::jit::getGraphExecutorOptimize()'
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/runtime/graph_executor.h:119: undefined reference to `torch::jit::setGraphExecutorOptimize(bool)'
CMakeFiles/Predictor.dir/predictor.cpp.o: In function `torch::jit::Module::forward(std::__ndk1::vector<c10::IValue, std::__ndk1::allocator<c10::IValue> >)':
/home/anussark/pytorch/build_android/install/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&) const'
CMakeFiles/Predictor.dir/predictor.cpp.o: In function `~Method':
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/method.h:22: undefined reference to `vtable for torch::jit::Method'
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/method.h:22: undefined reference to `vtable for torch::jit::Method'
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/method.h:22: undefined reference to `vtable for torch::jit::Method'
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/method.h:22: undefined reference to `vtable for torch::jit::Method'
CMakeFiles/Predictor.dir/predictor.cpp.o: In function `torch::jit::Object::get_method(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&) const':
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/object.h:102: undefined reference to `torch::jit::Object::find_method(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&) const'
CMakeFiles/Predictor.dir/predictor.cpp.o: In function `Method':
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/method.h:22: undefined reference to `vtable for torch::jit::Method'
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/method.h:22: undefined reference to `vtable for torch::jit::Method'
CMakeFiles/Predictor.dir/predictor.cpp.o: In function `~Method':
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/method.h:22: undefined reference to `vtable for torch::jit::Method'
/home/anussark/pytorch/build_android/install/include/torch/csrc/jit/api/method.h:22: undefined reference to `vtable for torch::jit::Method'
Checking out pytorch 1.7 worked for me (ndk 21e, not sure if that matters though)
Hi, I have the same issue. Have you sloved it? Many thanks in advance.
Hi @leigao97 I couldn't find the fix in my previous company. I am in a new company now :)
@anusrees @leigao97 Can confirm pytorch 1.7 + ndk 21.4.7075529 works. You need to run after checking out 1.7:
git submodule sync
git submodule update --init --recursive