# Undefined symbol: \_ZN2cv5errorEiRKSsPKcS3\_i

**URL:** <https://forum.opencv.org/t/undefined-symbol-zn2cv5erroreirksspkcs3-i/8050>\
**Category:** Uncategorized\
**Tags:** build\
**Created:** [March 22, 2022, 12:41pm UTC](https://forum.opencv.org/t/undefined-symbol-zn2cv5erroreirksspkcs3-i/8050 "2022-03-22T12:41:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stx000](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@stx000](https://forum.opencv.org/u/stx000)\
**Post date:** [March 22, 2022, 12:41pm UTC](https://forum.opencv.org/t/undefined-symbol-zn2cv5erroreirksspkcs3-i/8050/1 "2022-03-22T12:41:02Z")

</div>

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:

```auto
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:

```auto
>>> 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

```

---

<div class="post-metadata">

**Author:** ![mcg](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@mcg](https://forum.opencv.org/u/mcg)\
**Post date:** [October 5, 2022, 2:26pm UTC](https://forum.opencv.org/t/undefined-symbol-zn2cv5erroreirksspkcs3-i/8050/2 "2022-10-05T14:26:39Z")

</div>

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](http://demangler.com/) 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)](https://github.com/opencv/opencv/blob/4.5.5/modules/core/src/system.cpp#L1247)), which is indeed defined in libopencv\_core.so.

---

<div class="post-metadata">

**Author:** ![lingbo\_yu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lingbo_yu/32/10899_2.png) [@lingbo\_yu](https://forum.opencv.org/u/lingbo_yu)\
**Post date:** [August 6, 2024, 8:30am UTC](https://forum.opencv.org/t/undefined-symbol-zn2cv5erroreirksspkcs3-i/8050/3 "2024-08-06T08:30:39Z")

</div>

> [@stx000](#):
>
> suggestions

@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.
