Libtorch 'Scalar' type seems conflict with OpenCV 'Scalar'

username: haha
cooked: <p>I want to integrate libtorch into my existing ROS package in C++. However, I received a lot of errors like below. I also tested with the example provided by PyTorch and it worked very well. It seems that libtorch ‘Scalar’ type conflicts with the OpenCV ‘Scalar’ in my ROS package that is a also shared library. Did anyone meet this problem before?</p>
<p>Libtorch: master branch, built from source<br>
CUDA: disabled<br>
OpenCV: 3.4<br>
System: Ubuntu 18.04<br>
GCC: 7.5.0<br>
ROS: melodic</p>
<pre><code class="lang-auto">In file included from /usr/local/include/ATen/Tensor.h:3:0,
                 from /usr/local/include/ATen/Context.h:4,
                 from /usr/local/include/ATen/ATen.h:9,
                 from /usr/local/include/torch/csrc/api/include/torch/types.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/all.h:8,
                 from /usr/local/include/torch/csrc/api/include/torch/torch.h:3,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/include/tt_trajectory_prediction/trajectorypredictorrnn.h:8,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/src/lib/trajectorypredictorrnn.cpp:1:
/usr/local/include/ATen/core/TensorBody.h:258:21: error: declaration of 'operator=' as non-function
   Tensor&amp; operator=(Scalar v) &amp;&amp;;
                     ^~~~~~
/usr/local/include/ATen/core/TensorBody.h:258:19: error: expected ';' at end of member declaration
   Tensor&amp; operator=(Scalar v) &amp;&amp;;
                   ^
/usr/local/include/ATen/core/TensorBody.h:258:28: error: expected ')' before 'v'
   Tensor&amp; operator=(Scalar v) &amp;&amp;;
                            ^
In file included from /usr/local/include/ATen/Tensor.h:3:0,
                 from /usr/local/include/ATen/Context.h:4,
                 from /usr/local/include/ATen/ATen.h:9,
                 from /usr/local/include/torch/csrc/api/include/torch/types.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/all.h:8,
                 from /usr/local/include/torch/csrc/api/include/torch/torch.h:3,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/include/tt_trajectory_prediction/trajectorypredictorrnn.h:8,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/src/lib/trajectorypredictorrnn.cpp:1:
/usr/local/include/ATen/core/TensorBody.h:620:22: error: declaration of 'operator+=' as non-function
   Tensor&amp; operator+=(Scalar other);
                      ^~~~~~
/usr/local/include/ATen/core/TensorBody.h:620:19: error: expected ';' at end of member declaration
   Tensor&amp; operator+=(Scalar other);
                   ^~
/usr/local/include/ATen/core/TensorBody.h:620:29: error: expected ')' before 'other'
   Tensor&amp; operator+=(Scalar other);
                             ^~~~~
/usr/local/include/ATen/core/TensorBody.h:622:22: error: declaration of 'operator-=' as non-function
   Tensor&amp; operator-=(Scalar other);
                      ^~~~~~
/usr/local/include/ATen/core/TensorBody.h:622:19: error: expected ';' at end of member declaration
   Tensor&amp; operator-=(Scalar other);
                   ^~
/usr/local/include/ATen/core/TensorBody.h:622:29: error: expected ')' before 'other'
   Tensor&amp; operator-=(Scalar other);
                             ^~~~~
/usr/local/include/ATen/core/TensorBody.h:624:22: error: declaration of 'operator*=' as non-function
   Tensor&amp; operator*=(Scalar other);
                      ^~~~~~
/usr/local/include/ATen/core/TensorBody.h:624:19: error: expected ';' at end of member declaration
   Tensor&amp; operator*=(Scalar other);
                   ^~
/usr/local/include/ATen/core/TensorBody.h:624:29: error: expected ')' before 'other'
   Tensor&amp; operator*=(Scalar other);
                             ^~~~~
/usr/local/include/ATen/core/TensorBody.h:626:22: error: declaration of 'operator/=' as non-function
   Tensor&amp; operator/=(Scalar other);
                      ^~~~~~
/usr/local/include/ATen/core/TensorBody.h:626:19: error: expected ';' at end of member declaration
   Tensor&amp; operator/=(Scalar other);
                   ^~
/usr/local/include/ATen/core/TensorBody.h:626:29: error: expected ')' before 'other'
   Tensor&amp; operator/=(Scalar other);
                             ^~~~~
/usr/local/include/ATen/core/TensorBody.h:630:21: error: reference to 'Scalar' is ambiguous
   Tensor operator[](Scalar index) const;
                     ^~~~~~
In file included from /usr/local/include/ATen/Operators.h:5:0,
                 from /usr/local/include/ATen/core/TensorBody.h:3,
                 from /usr/local/include/ATen/Tensor.h:3,
                 from /usr/local/include/ATen/Context.h:4,
                 from /usr/local/include/ATen/ATen.h:9,
                 from /usr/local/include/torch/csrc/api/include/torch/types.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/all.h:8,
                 from /usr/local/include/torch/csrc/api/include/torch/torch.h:3,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/include/tt_trajectory_prediction/trajectorypredictorrnn.h:8,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/src/lib/trajectorypredictorrnn.cpp:1:
/usr/local/include/c10/core/Scalar.h:27:15: note: candidates are: class c10::Scalar
 class C10_API Scalar {
               ^~~~~~
In file included from /usr/local/include/opencv2/core.hpp:58:0,
                 from /usr/local/include/opencv2/core/core.hpp:48,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/include/tt_trajectory_prediction/trajectorypredictorrnn.h:4,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/src/lib/trajectorypredictorrnn.cpp:1:
/usr/local/include/opencv2/core/types.hpp:657:25: note:                 typedef class cv::Scalar_&lt;double&gt; cv::Scalar
 typedef Scalar_&lt;double&gt; Scalar;
                         ^~~~~~
In file included from /usr/local/include/ATen/Tensor.h:3:0,
                 from /usr/local/include/ATen/Context.h:4,
                 from /usr/local/include/ATen/ATen.h:9,
                 from /usr/local/include/torch/csrc/api/include/torch/types.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data/dataloader.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/data.h:3,
                 from /usr/local/include/torch/csrc/api/include/torch/all.h:8,
                 from /usr/local/include/torch/csrc/api/include/torch/torch.h:3,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/include/tt_trajectory_prediction/trajectorypredictorrnn.h:8,
                 from /data_disk/apps/2021/tt_robot/src/tt_tracking_system/tt_trajectory_prediction/src/lib/trajectorypredictorrnn.cpp:1:
/usr/local/include/ATen/core/TensorBody.h:630:21: error: 'Scalar' has not been declared
   Tensor operator[](Scalar index) const;
                     ^~~~~~
/usr/local/include/ATen/core/TensorBody.h:638:74: error: reference to 'Scalar' is ambiguous
   Tensor &amp; index_put_(ArrayRef&lt;at::indexing::TensorIndex&gt; indices, const Scalar&amp; v);
                                                                          ^~~~~~`
</code></pre>