Help building cpp code with opencv

I run into the following error when I try to compile a modified version of this project: GitHub - Wizaron/pytorch-cpp-inference: Serving PyTorch 1.0 Models as a Web Server in C++

I’m using the unzipped libtorch from Pytorch’s website. And here’s my CMakeLists.txt

make_minimum_required(VERSION 3.0 FATAL_ERROR)
project(cnn-classification)

find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)

add_executable(cnn-inference main.cc infer.cc ../../utils/opencvutils.cc ../../utils/torchutils.cc)

target_link_libraries(cnn-inference "${TORCH_LIBRARIES}")
target_link_libraries(cnn-inference "${OpenCV_LIBS}")

message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")


set_property(TARGET cnn-inference PROPERTY CXX_STANDARD 11)
#set_property(TARGET cnn-inference PROPERTY OUTPUT_NAME predict)

set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

Could someone help me with these linkage errors? Do I need to compile libtorch from source?

Thanks! :slight_smile:

This can be due to ABI-incompatibility issue. You might want to try compiling libtorch from source, and make sure you are using the same compiler to compile both opencv and libtorch.

We now have new ABI binaries for libtorch. They can be found on
http://pytorch.org, or at https://github.com/pytorch/pytorch/issues/17492#issuecomment-524692441. It should fix the problem.

See my response here:

I used a pre-compiled OpenCV version. This is the only solution that worked for me.