Compilation error in 'jit/ir/ir.h'

username: Aviais
cooked: <p>Hi,<br>
I’m trying to include PyTorch library in my CPP project.<br>
I’m using ndk21 and C++14, torch version 1.5.0 for CPU.</p>
<p>I get the following compilation errors, all from csrc/jit/ir/ir.h and regarding c10 namespace:</p>
<p>C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:67:17: error: no<br>
namespace named ‘prim’ in namespace ‘c10’; did you mean simply ‘prim’?<br>
using namespace ::c10::prim;<br>
^~~~~~~~~~~<br>
prim<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:66:11: note: namespace<br>
‘prim’ defined here<br>
namespace prim {<br>
^<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:70:17: error: no<br>
namespace named ‘attr’ in namespace ‘c10’; did you mean simply ‘attr’?<br>
using namespace ::c10::attr;<br>
^~~~~~~~~~~<br>
attr<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:69:11: note: namespace<br>
‘attr’ defined here<br>
namespace attr {<br>
^<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:73:17: error: no<br>
namespace named ‘aten’ in namespace ‘c10’; did you mean simply ‘aten’?<br>
using namespace ::c10::aten;<br>
^~~~~~~~~~~<br>
aten<br>
C:\REPOSCPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:72:11: note: namespace<br>
‘aten’ defined here<br>
namespace aten {<br>
^<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:1309:34: error: no<br>
member named ‘prim’ in namespace ‘c10’; did you mean simply ‘prim’?<br>
static constexpr Symbol Kind = ::c10::prim::profile;<br>
^~~~~~~~~~~<br>
prim<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:66:11: note: ‘prim’<br>
declared here<br>
namespace prim {<br>
^<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:1309:47: error: no<br>
member named ‘profile’ in namespace ‘torch::jit::prim’<br>
static constexpr Symbol Kind = ::c10::prim::profile;<br>



^<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:1311:21: error: no<br>
member named ‘prim’ in namespace ‘c10’; did you mean simply ‘prim’?<br>
: Node(graph, ::c10::prim::profile), callback_(callback) {}<br>
^


~~~~<br>
prim<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:66:11: note: ‘prim’<br>
declared here<br>
namespace prim {<br>
^<br>
C:\REPOS\CPU\libtorch-shared-with-deps-latest\libtorch/include\torch/csrc/jit/ir/ir.h:1311:34: error: no<br>
member named ‘profile’ in namespace ‘torch::jit::prim’<br>
: Node(graph, ::c10::prim::profile), callback_(callback) {}</p>
<p>Can someone please help me to overcome this?<br>
Thanks.</p>

username: Aviais
cooked: <p><strong>More information:</strong></p>
<ol>
<li>I have a CPP android project. I’m compiling it using ndk-build (ndk21 and C++14).</li>
<li>I have a file named “main.cpp” and I’m trying to  <strong><span class="hashtag">#include</span> “torch/script.h”</strong> .</li>
<li>I downloaded libtorch using this command:<br>
<strong>wget <a href="https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz" rel="nofollow noopener">https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz</a></strong>
</li>
<li>In my Android.mk file, I’m giving the path to:<br>
LOCAL_C_INCLUDES += $(TORCH_REPO_PATH)<br>
$(TORCH_REPO_PATH)/include<br>
$(TORCH_REPO_PATH)/include/torch<br>
$(TORCH_REPO_PATH)/include/torch/csrc/api/include</li>
<li>When I’m trying to compile, I get the errors demonstrated above.<br>
How can I overcome this issue?</li>
</ol>

username: ljk53
cooked: <p>This question seems to be related to <a href="https://github.com/pytorch/pytorch/issues/38319" rel="nofollow noopener">https://github.com/pytorch/pytorch/issues/38319</a></p>
<p>Copy the options from there:</p>
<ol>
<li>You can use the prebuilt binaries we released for mobile, see details: <a href="https://pytorch.org/mobile/home/" rel="nofollow noopener">https://pytorch.org/mobile/home/</a>
</li>
<li>You can build it from source on your own for Android using the following script:</li>
</ol>
<pre><code class="lang-auto">scripts/build_pytorch_android.sh
</code></pre>
<ol start="3">
<li>If you don’t want to use the JNI wrapper, you can also use the C++ API directly from your Android C++ code. This is not officially supported yet, but here is a simple example: <a href="https://github.com/ljk53/pytorch-android-cpp-demo" rel="nofollow noopener">https://github.com/ljk53/pytorch-android-cpp-demo</a>
</li>
</ol>
<p>For option 1 &amp; option 2, you will get libtorch built in the form of Android AAR (<a href="https://stackoverflow.com/questions/23915619/android-archive-library-aar-vs-standard-jar" rel="nofollow noopener">https://stackoverflow.com/questions/23915619/android-archive-library-aar-vs-standard-jar</a>), which provides Java API and can be called from your Java code on Android.</p>
<p>If you want to call libtorch C++ API in your mobile app directly, you can try Option 3 (which is not well supported yet) - please check out the example code and follow README to see how it works.</p>

username: Aviais
cooked: <p>Hello <a class="mention" href="/u/ljk53">@ljk53</a>,<br>
Thank you for your help.</p>
<ul>
<li>I was able to run my model using the JAVA example.</li>
<li>I was able to execute the “pytorch-android-cpp-demo” on my Android device. Now I’m trying to use the generated binaries in my cpp android project.</li>
</ul>
<p>Can you please tell me what can be done to compile the binaries for arm64? I would like to get .so files and not static libraries.</p>

username: xtremesky
cooked: <p>Hi, I got exactly the same error as this post. I am using Pytorch 1.6. The codes I include works well on Mac, Linux, Windows, but fail on NDK. Any hint? Thanks.</p>