Undefined symbol: _ZN2cv5errorEiRKSsPKcS3_i

When i import my python module which implements a image process unit using c++ Opencv and Pybind11, i got this error. I have tried the version of 4.0.0/4.1.0/4.1.2/4.2.0/4.3.0/4.4.0 and got the same result. However, when i update the version to 4.5, the error gone. I want to fix this problem since version 4.5 has harm my code performance. Any suggestions would be grateful! My CMakeLists.txt is shown below:

project(dbpost_module LANGUAGES CXX)
cmake_minimum_required(VERSION 3.12)

find_package(pybind11 REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Torch REQUIRED)


message(STATUS "Pytorch status:")
message(STATUS "    libraries: ${TORCH_LIBRARIES}")

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

include_directories(${PYTHON_INCLUDE_DIRS} ${_numpy_include_dirs} ${OpenCV_INCLUDE_DIRS})
include_directories("/usr/local/lib/")

message("Python libs: ${PYTHON_LIBRARIES}")

find_library(TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib")
message(STATUS "TORCH_PYTHON_LIBRARY: ${TORCH_PYTHON_LIBRARY}")


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

pybind11_add_module(dbpost_module dbpost_module.cpp)

target_link_libraries(dbpost_module PUBLIC ${OpenCV_LIBS} PUBLIC ${TORCH_LIBRARIES} PUBLIC ${TORCH_PYTHON_LIBRARY})

set_property(TARGET dbpost_module PROPERTY CXX_STANDARD 14)

Result:

>>> import torch
>>> import dbpost_module
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /home/***/inference/new_ocr/svrep_git/models/post_processing/db_post_cpp/build/dbpost_module.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN2cv5errorEiRKSsPKcS3_i

It seems to be an issue with compiler/ABI compatibility, try using a newer compiler.

Notes from trying to find the cause – take with a grain of salt as I bumped into the same error with just OpenCV 4.5.5 and pybind11, without a build system:
The _ZN2cv5errorEiRKSsPKcS3_i (demangled is cv::error(int, std::string const&, char const*, char const*, int)), which was generated for me when using an ancient GCC 4.8.5, does not seem to be present in the pre-compiled OpenCV libraries I got from conda.
When I compiled my program with GCC 11.2.0, the resulting symbol is _ZN2cv5errorEiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKcS9_i (or cv::error(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, char const*, int) or void error(int _code, const String& _err, const char* _func, const char* _file, int _line)), which is indeed defined in libopencv_core.so.

@stx000 hello,I met the same problem when I use pytorch and opencv. Have you solved this issue.
I would really appreciate any help and advice you can offer.