I installed OpenCV 4.5.0 for a C++ project, and for some reason after running it gives me the following error:
undefined symbol: _ZN2cv7imwriteERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayERKSt6vectorIiSaIiEE
The demangled part is :
cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)
I tried several includes (
opencv.hpp, core.hpp, imgcodecs.hpp, highgui.hpp), nothing helped.
I then tried to run the following command:
nm -g /usr/lib/aarch64-linux-gnu/libopencv_imgcodecs.so | grep imwrite on a freshly flashed Nano, got the same error.
Does anyone have an idea what could be the issue?
You would have to link to opencv_imgcodecs and stdc++ libraries:
-lopencv_core -lopencv_imgcodecs -lstdc++
Tried it, doesn’t seem to help. Maybe I’m doing something wrong in my makefile? here it is:
CXX = g++
INCLUDES = -Iinclude -I /home/jetson/Desktop/Drone-Nav/VNSensorHandler/vnproglib/cpp/include -I /home/jetson/.local/lib/python3.6/site-packages/cppyy_backend/include
CPPFLAGS = -Wall
CXXFLAGS = -std=c++11 -fPIC -g -Wall -pedantic `pkg-config --cflags opencv4`
LIBS = `pkg-config --libs opencv4`
BINDIR = build/bin
OBJDIR = build/obj
LDFLAGS = -shared
SOURCES = \
# Set the object file names, with the source directory stripped
# from the path, and the build path prepended in its place
OBJECTS = $(SOURCES:source/%.cpp=$(OBJDIR)/%.o)
all: dirs lib
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LIBS) -lopencv_core -lopencv_imgcodecs -lstdc++ -o $(BINDIR)/main.so $(OBJECTS)
# Create the directories used in the build
@mkdir -p $(BINDIR)
@mkdir -p $(OBJDIR)
@mkdir -p $(dir $(OBJECTS))
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LIBS) -lopencv_core -lopencv_imgcodecs -lstdc++ $(INCLUDES) -c $< -o $@
rm -f $(OBJECTS)
These would only be relevant for linking, not for compiling.
pkg-config --libs opencv4
Did you install your opencv-4.5.0 build into a non standard path ?
I also notice that you’re linking into a shared library. Maybe this is related, but I’m unable to try for now.
Okay I figured it out, it was not related to OpenCV or the Nano, but to the package cppyy I’m using to create a Python wrapper, I had to load the library
opencv_imgcodecs there too. My mistake.
Sorry for the trouble, and thanks anyway!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.