Libtorch throws some errors when using toghether with qt, pcl and opencv

username: Mircea_Paul_Muresan
cooked: <p>I am trying to use libtorch, qt widgets, point cloud library(pcl) and opencv in a project. For this project I am  using cmake lists. The issue is that when I am using all four libraries together errors are thrown by libtorch. If I use libtorch, opencv and qt everything works fine, also if I use pcl qt and opencv everything also works well. The errors that I get are listed bellow:</p>
<ol>
<li>/libtorch/include/torch/csrc/jit/api/object.h: In member function ‘size_t torch::jit::Object::num_slots() const’:<br>
/libtorch/include/torch/csrc/jit/api/object.h:173:28: error: expected unqualified-id before ‘(’ token  173 return _ivalue()-&gt;slots().size();</li>
<li>/libtorch/include/ATen/core/ivalue_inl.h: In member function ‘c10::intrusive_ptr c10::IValue::toCustomClass() const &amp;’:<br>
/libtorch/include/ATen/core/ivalue_inl.h:1642:3: error: expected unqualified-id before ‘(’ token<br>
1642 |   TORCH_CHECK(</li>
<li>/libtorch/include/ATen/core/ivalue_inl.h: In member function ‘c10::intrusive_ptr c10::IValue::toCustomClass() &amp;&amp;’:<br>
/libtorch/include/ATen/core/ivalue_inl.h:1624:3: error: expected unqualified-id before ‘(’ token<br>
1624 |   TORCH_CHECK(<br>
|   ^~~~~~~~~~~</li>
<li>/libtorch/include/ATen/core/ivalue_inl.h:1419:36: error: expected unqualified-id before ‘)’ token<br>
1419 |   const std::vector&amp; slots() const {</li>
</ol>
<p>Does anyone know why libtorch is trowing these errors?</p>

username: pi-null-mezon
cooked: <p>Hi. I have same issue when use only Qt and Torch in same build. Furthermore compile error appears only when specific Qt classes included in main.cpp. For the instance:</p>
<ul>
<li>compiles successfully</li>
</ul>
<pre><code class="lang-auto">#include &lt;QString&gt;
#include &lt;torch/script.h&gt;
</code></pre>
<ul>
<li>does not compiles (…ivalue_inl.h:1419:36: error: expected unqualified-id before ‘)’ token…)</li>
</ul>
<pre><code class="lang-auto">#include &lt;QFileInfo&gt;
#include &lt;torch/script.h&gt;
</code></pre>

username: pi-null-mezon
cooked: <p>So, I have tried to include Qt’s classes after Torch and now my project compiles fine</p>
<ul>
<li>compiles successfully</li>
</ul>
<pre><code class="lang-auto">#include &lt;torch/script.h&gt;
#include &lt;QFileInfo&gt;
</code></pre>
<p>It seems that the problem is in the order of the inclusitions</p>

username: Mircea_Paul_Muresan
cooked: <p>I have solved this issue. Bellow you can find the solution that worked for me.</p><aside class="onebox stackexchange" data-onebox-src="https://stackoverflow.com/questions/72533139/libtorch-errors-when-used-with-qt-opencv-and-point-cloud-library">
  <header class="source">

      <a href="https://stackoverflow.com/questions/72533139/libtorch-errors-when-used-with-qt-opencv-and-point-cloud-library" target="_blank" rel="noopener nofollow ugc">stackoverflow.com</a>
  </header>

  <article class="onebox-body">
      <a href="https://stackoverflow.com/users/2302877/mircea-paul-muresan" target="_blank" rel="noopener nofollow ugc">
    <img alt="Mircea Paul Muresan" src="https://i.stack.imgur.com/t5G0L.jpg?s=256&amp;g=1" class="thumbnail onebox-avatar" width="256" height="256">
  </a>

<h4>
  <a href="https://stackoverflow.com/questions/72533139/libtorch-errors-when-used-with-qt-opencv-and-point-cloud-library" target="_blank" rel="noopener nofollow ugc">Libtorch errors when used with QT, OpenCV and Point Cloud Library</a>
</h4>

<div class="tags">
  <strong>c++, opencv, qt-creator, point-cloud-library</strong>
</div>

<div class="date">
  asked by
  
  <a href="https://stackoverflow.com/users/2302877/mircea-paul-muresan" target="_blank" rel="noopener nofollow ugc">
    Mircea Paul Muresan
  </a>
  on <a href="https://stackoverflow.com/questions/72533139/libtorch-errors-when-used-with-qt-opencv-and-point-cloud-library" target="_blank" rel="noopener nofollow ugc">02:37PM - 07 Jun 22 UTC</a>
</div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>