Pytorch/torch/csrc/api/src/serialize/output-archive.cpp:39: error: undefined reference to 'torch::jit::ExportModule

username: Suresh
cooked: <p>Hi,<br>
Below is my C++ code</p>
<p><span class="hashtag">#include</span> &lt;torch/torch.h&gt;<br>
<span class="hashtag">#include</span> &lt;torch/script.h&gt; // One-stop header.</p>
<p><span class="hashtag">#include</span> <br>
<span class="hashtag">#include</span> </p>
<p>struct ID : torch::nn::Module {};<br>
using namespace std;</p>
<p>int main()<br>
{<br>
auto test = std::make_shared();<br>
//torch::load(spkr_id,“net.pt”);<br>
torch::save(test,“net.pt”);<br>
}</p>
<p>I’m getting Linkage error As I’m running on the Android Platform with cross-compiled PyTorch libraries</p>
<p>rm: cannot remove ‘pytorch_app’: No such file or directory<br>
– Check for working CXX compiler: /home/suresh/ANdroid_NEW_NDK/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++<br>
– Check for working CXX compiler: /home/suresh/ANdroid_NEW_NDK/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ – works<br>
– Detecting CXX compiler ABI info<br>
– Detecting CXX compiler ABI info - done<br>
– Detecting CXX compile features</p>
<p>– Detecting CXX compile features - done<br>
– Configuring done<br>
– Generating done<br>
– Build files have been written to: /home/suresh/spkrid_ali/spkrid_jio/testsrc/android/build<br>
Scanning dependencies of target pytorch_app<br>
[ 25%] Building CXX object CMakeFiles/pytorch_app.dir/src/mian.cpp.o<br>
[ 50%] Building CXX object CMakeFiles/pytorch_app.dir/src/test.cpp.o<br>
[ 75%] Building CXX object CMakeFiles/pytorch_app.dir/src/test_nn.cpp.o<br>
[100%] Linking CXX executable pytorch_app<br>
/home/suresh/pytorch/torch/csrc/api/src/serialize/output-archive.cpp:39: error: undefined reference to ‘torch::jit::ExportModule(torch::jit::script::Module const&amp;, std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits, std::__ndk1::allocator &gt; const&amp;, std::__ndk1::unordered_map&lt;std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits, std::__ndk1::allocator &gt;, std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits, std::__ndk1::allocator &gt;, std::__ndk1::hash&lt;std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits, std::__ndk1::allocator &gt; &gt;, std::__ndk1::equal_to&lt;std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits, std::__ndk1::allocator &gt; &gt;, std::__ndk1::allocator&lt;std::__ndk1::pair&lt;std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits, std::__ndk1::allocator &gt; const, std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits, std::__ndk1::allocator &gt; &gt; &gt; &gt; const&amp;, bool)’<br>
clang++: error: linker command failed with exit code 1 (use -v to see invocation)<br>
CMakeFiles/pytorch_app.dir/build.make:157: recipe for target ‘pytorch_app’ failed<br>
make[2]: *** [pytorch_app] Error 1<br>
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/pytorch_app.dir/all’ failed<br>
make[1]: *** [CMakeFiles/pytorch_app.dir/all] Error 2<br>
Makefile:83: recipe for target ‘all’ failed<br>
make: *** [all] Error 2</p>

username: Suresh
cooked: <p>for “torch:: load(test, “net.pt”);” Compilation &amp; Linking got successful, But I’m stuck in torch:: save() API, is there any wrong in implementation or else definitions in the torch library is not compiled?</p>
<p>Please help me because I’m new to this. Thanks in Advance.</p>

username: David_Reiss
cooked: <p>Our Android builds currently exclude the code for saving because they are intended for inference.</p>

username: chan_z
cooked: <p>Yes, thanks for all your work. Why dont you remove the excluded head files to avoid this confusion. And … How can i save tensor in android ndk libtorch version <img src="https://discuss.pytorch.org/images/emoji/apple/melting_face.png?v=12" title=":melting_face:" class="emoji" alt=":melting_face:" loading="lazy" width="20" height="20"></p>