How to succeed use LibTorch with OpenCV?

username: LvJC
cooked: <p>Cannoooooot build successfully!</p>
<ul>
<li>
<p>1st trial:<br>
using <code>pip3.6 install</code> to install pytorch1.0 and download libtorch zip file.<br>
cannot use it with opencv, throwing error of <code>undefined error imread</code></p>
</li>
<li>
<p>2nd trial<br>
build from source! Always report this:</p>
</li>
</ul>
<pre><code class="lang-auto">Install the project... 
-- Install configuration: "Release" 

-- Set runtime path of "/data/lvjc/pytorch/torch/lib/tmp_install/lib/libmkldnn.so.0.17.0" to "$ORIGIN:/data/lvjc/envs/anaconda2/lib" 

-- Set runtime path of "/data/lvjc/pytorch/torch/lib/tmp_install/lib/libc10.so" to "$ORIGIN" 

-- Set runtime path of "/data/lvjc/pytorch/torch/lib/tmp_install/lib/libc10_cuda.so" to "$ORIGIN" 

-- Set runtime path of "/data/lvjc/pytorch/torch/lib/tmp_install/lib/libcaffe2.so" to "$ORIGIN:/data/lvjc/envs/anaconda2/lib:/usr/local/cuda/lib64" 

-- Set runtime path of "/data/lvjc/pytorch/torch/lib/tmp_install/lib/libcaffe2_gpu.so" to "$ORIGIN:/data/lvjc/envs/anaconda2/lib:/usr/local/cuda/lib64" 

-- Set runtime path of "/data/lvjc/pytorch/torch/lib/tmp_install/lib/libtorch.so.1" to "$ORIGIN:/usr/local/cuda/lib64:/data/lvjc/envs/anaconda2/lib" 

-- Set runtime path of "/data/lvjc/pytorch/torch/lib/tmp_install/lib/libcaffe2_module_test_dynamic.so" to "$ORIGIN:/data/lvjc/envs/anaconda2/lib" 

ls: cannot access 'build.ninja': No such file or directory
</code></pre>

username: ptrblck
cooked: <p>I can understand some frustration, but am not a big fan of offensive language.<br>
I’ve edited the topic and your post.</p>
<p>Could you post your install steps and <code>CMakeFiles.txt</code>?<br>
The current information is a bit sparse.</p>

username: LvJC
cooked: <p>I have tried soooo hard to build again and again. I will show you.<br>
Setups:</p>
<ul>
<li>Docker version 18.06.1-ce, build e68fc7a</li>
<li>CUDA 9.0</li>
<li>Anaconda 3</li>
<li>CMAKE 3.11.1 (conda)</li>
<li>GCC G++ 5.4</li>
<li>Build PyTorch from source</li>
<li>Download LibTorch from official site(tried from source but receive error <code>ls: cannot access 'build.ninja': No such file or directory</code>)</li>
<li>OpenCV3.4.1 from <code>conda install opencv</code> (have tried build version 4.0.0 from source but received error <code>target opencv_ts; Makefile:162: recipe for target 'all' failed; make: *** [all] Error 2</code>)</li>
</ul>
<p>Now I want to try run this demo using libtorch <a href="https://github.com/iamhankai/cpp-pytorch" rel="nofollow noopener">https://github.com/iamhankai/cpp-pytorch</a><br>
But I am always RECEIVING ERROR!<br>
This is <code>CMakeLists.txt</code>:</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(custom_ops)

find_package(Torch REQUIRED)

find_package( OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable(example-app example-app.cpp)
target_link_libraries(example-app ${TORCH_LIBRARIES} ${OpenCV_LIBS})
set_property(TARGET example-app PROPERTY CXX_STANDARD 11)
</code></pre>

username: ptrblck
cooked: <p>Thanks for the info.<br>
As far as I know you won’t be able to include OpenCV in your C++ application by using the <code>conda</code> version, but would need to build it.<br>
It looks currently as if your issue is related to OpenCV.<br>
To get a better error message, you might run the build with <code>make VERBOSE=1</code>.</p>