You need C++14 to compile PyTorch

username: dalalaa
cooked: <p>I followed the instruction of <a href="https://github.com/pytorch/extension-script" rel="nofollow noopener">pytorch/extension-script</a> to register custom c++ operator.</p>
<p>But I changed the version of PyTorch because my network speed is poor. My Dockerfile is as follows:</p>
<pre><code class="lang-auto">FROM ubuntu:xenial

RUN apt-get update  -y \
  &amp;&amp; apt-get install -y git cmake vim make wget gnupg build-essential software-properties-common gdb zip

# Install OpenCV
RUN apt-get install -y libopencv-dev

# Install Miniconda
RUN wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh \
  &amp;&amp; chmod +x miniconda.sh \
  &amp;&amp; ./miniconda.sh -b -p ~/local/miniconda \
  &amp;&amp; rm ./miniconda.sh

# Symlink the Miniconda activation script to /activate
RUN ln -s ~/local/miniconda/bin/activate /activate
# Install PyTorch
RUN . /activate &amp;&amp; conda install pytorch torchvision cpuonly -c pytorch

# Download LibTorch
RUN wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
RUN unzip libtorch-shared-with-deps-latest.zip &amp;&amp; rm libtorch-shared-with-deps-latest.zip

WORKDIR /home

</code></pre>
<p>I changed this line:<br>
<strong>RUN . /activate &amp;&amp; conda install pytorch torchvision cpuonly -c pytorch</strong></p>
<p>When I run : <code>make -j</code>, I got following error:</p>
<pre><code class="lang-auto">(base) root@4c6b54e7fed4:/home/example_app/build# make -j
Scanning dependencies of target warp_perspective
[ 25%] Building CXX object warp_perspective/CMakeFiles/warp_perspective.dir/op.cpp.o
In file included from /libtorch/include/c10/util/ArrayRef.h:19:0,
                 from /libtorch/include/c10/core/MemoryFormat.h:5,
                 from /libtorch/include/ATen/core/TensorBody.h:5,
                 from /libtorch/include/ATen/Tensor.h:11,
                 from /libtorch/include/ATen/Context.h:4,
                 from /libtorch/include/ATen/ATen.h:5,
                 from /libtorch/include/torch/csrc/api/include/torch/types.h:3,
                 from /libtorch/include/torch/script.h:3,
                 from /home/example_app/warp_perspective/op.cpp:2:
/libtorch/include/c10/util/C++17.h:20:2: error: #error You need C++14 to compile PyTorch
 #error You need C++14 to compile PyTorch
  ^
/home/example_app/warp_perspective/op.cpp: In function 'at::Tensor warp_perspective(at::Tensor, at::Tensor)':
/home/example_app/warp_perspective/op.cpp:54:48: warning: 'T* at::Tensor::data() const [with T = float]' is deprecated [-Wdeprecated-declarations]
                     /*data=*/image.data&lt;float&gt;());
                                                ^
In file included from /libtorch/include/ATen/Tensor.h:11:0,
                 from /libtorch/include/ATen/Context.h:4,
                 from /libtorch/include/ATen/ATen.h:5,
                 from /libtorch/include/torch/csrc/api/include/torch/types.h:3,
                 from /libtorch/include/torch/script.h:3,
                 from /home/example_app/warp_perspective/op.cpp:2:
/libtorch/include/ATen/core/TensorBody.h:322:7: note: declared here
   T * data() const {
       ^
/home/example_app/warp_perspective/op.cpp:58:46: warning: 'T* at::Tensor::data() const [with T = float]' is deprecated [-Wdeprecated-declarations]
                    /*data=*/warp.data&lt;float&gt;());
                                              ^
In file included from /libtorch/include/ATen/Tensor.h:11:0,
                 from /libtorch/include/ATen/Context.h:4,
                 from /libtorch/include/ATen/ATen.h:5,
                 from /libtorch/include/torch/csrc/api/include/torch/types.h:3,
                 from /libtorch/include/torch/script.h:3,
                 from /home/example_app/warp_perspective/op.cpp:2:
/libtorch/include/ATen/core/TensorBody.h:322:7: note: declared here
   T * data() const {
       ^
/home/example_app/warp_perspective/op.cpp: At global scope:
/home/example_app/warp_perspective/op.cpp:69:78: error: no matching function for call to 'torch::jit::RegisterOperators::RegisterOperators(const char [25], at::Tensor (*)(at::Tensor, at::Tensor))'
   torch::jit::RegisterOperators("my_ops::warp_perspective", &amp;warp_perspective);
                                                                              ^
In file included from /libtorch/include/torch/script.h:6:0,
                 from /home/example_app/warp_perspective/op.cpp:2:
/libtorch/include/torch/csrc/jit/custom_operator.h:20:3: note: candidate: torch::jit::RegisterOperators::RegisterOperators(std::vector&lt;torch::jit::Operator&gt;)
   RegisterOperators(std::vector&lt;Operator&gt; operators) {
   ^
/libtorch/include/torch/csrc/jit/custom_operator.h:20:3: note:   candidate expects 1 argument, 2 provided
/libtorch/include/torch/csrc/jit/custom_operator.h:17:3: note: candidate: constexpr torch::jit::RegisterOperators::RegisterOperators()
   RegisterOperators() = default;
   ^
/libtorch/include/torch/csrc/jit/custom_operator.h:17:3: note:   candidate expects 0 arguments, 2 provided
/libtorch/include/torch/csrc/jit/custom_operator.h:16:18: note: candidate: constexpr torch::jit::RegisterOperators::RegisterOperators(const torch::jit::RegisterOperators&amp;)
 struct TORCH_API RegisterOperators {
                  ^
/libtorch/include/torch/csrc/jit/custom_operator.h:16:18: note:   candidate expects 1 argument, 2 provided
/libtorch/include/torch/csrc/jit/custom_operator.h:16:18: note: candidate: constexpr torch::jit::RegisterOperators::RegisterOperators(torch::jit::RegisterOperators&amp;&amp;)
/libtorch/include/torch/csrc/jit/custom_operator.h:16:18: note:   candidate expects 1 argument, 2 provided
warp_perspective/CMakeFiles/warp_perspective.dir/build.make:62: recipe for target 'warp_perspective/CMakeFiles/warp_perspective.dir/op.cpp.o' failed
make[2]: *** [warp_perspective/CMakeFiles/warp_perspective.dir/op.cpp.o] Error 1
CMakeFiles/Makefile2:122: recipe for target 'warp_perspective/CMakeFiles/warp_perspective.dir/all' failed
make[1]: *** [warp_perspective/CMakeFiles/warp_perspective.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
</code></pre>
<p>How can I fix this problem? Looking forward to your replay.</p>

username: rilesdg3
cooked: <p>I just had a similar problem</p>
<p>Your c++ compiler needs to support c++14, so if you have a version that does not support c++14 then you will have to upgrade to one that does.</p>
<p>To check compiler version<br>
in a terminal type     <strong>gcc --version</strong></p>
<p>Looking at this page <a href="https://gcc.gnu.org/projects/cxx-status.html" rel="nofollow noopener">https://gcc.gnu.org/projects/cxx-status.html</a> I am guessing if you compiler is not &gt;= version 4.9 then you will need to upgrade it</p>
<p>If your compiler does support c++14 then you need to set a flag to -std=c++14 to tell the compiler to use c++14</p>
<p>if building from source I think you would do the following</p>
<p>in CMakeCache.txt file find <strong>CMAKE_CXX_FLAGS:STRING=</strong> and set it to <strong>CMAKE_CXX_FLAGS:STRING=-std=c++14</strong><br>
or <strong>CMAKE_CXX_FLAGS:STRING=-std=c++1y</strong></p>
<p>or take a look at this</p>
<aside class="onebox stackexchange">
  <header class="source">
      <a href="https://stackoverflow.com/questions/44284275/passing-compiler-options-cmake" target="_blank" rel="nofollow noopener">stackoverflow.com</a>
  </header>
  <article class="onebox-body">
      <a href="https://stackoverflow.com/users/1534898/infoclogged" target="_blank" rel="nofollow noopener">
    <img alt="infoclogged" src="https://www.gravatar.com/avatar/e96aa9237f776b2fdf6ca1b805ba48f8?s=128&amp;d=identicon&amp;r=PG" class="thumbnail onebox-avatar" width="128" height="128">
  </a>
<h4>
  <a href="https://stackoverflow.com/questions/44284275/passing-compiler-options-cmake" target="_blank" rel="nofollow noopener">Passing compiler options cmake</a>
</h4>

<div class="tags">
  <strong>cmake</strong>
</div>

<div class="date">
  asked by
  
  <a href="https://stackoverflow.com/users/1534898/infoclogged" target="_blank" rel="nofollow noopener">
    infoclogged
  </a>
  on <a href="https://stackoverflow.com/questions/44284275/passing-compiler-options-cmake" target="_blank" rel="nofollow noopener">12:02PM - 31 May 17 UTC</a>
</div>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


username: Alpha
cooked: <p>When building cutome extention module use the <code>setup.py</code>, you can specify:</p>
<pre><code class="lang-auto">extra_compile_args={'cxx': ['-std=c++14'], 'nvcc', [some_args]}
</code></pre>

username: mattpopovich
cooked: <p>I had similar issues compiling torchvision. I was using a compiler that supported C++14 and the CMakeLists.txt file had the correct flags set. The issue was with a CUDA flag that was getting set automatically. More info available at the issue I opened here: <a href="https://github.com/pytorch/vision/issues/4175" class="inline-onebox" rel="noopener nofollow ugc">Failing to compile torchvision C++ API from source (&gt;C++14 compiler required, which is installed) · Issue #4175 · pytorch/vision · GitHub</a></p>