I’ve already been having opencv python on my system for quite some time now for I work predominantly in python3. Now, however, I have been trying to run a repo written in C++ which uses opencv C++.
I didn’t install opencv C++ because I thought that opencv python is just a wrapper around opencv C++, so it must be having the code needed to run opencv C++ anyway.
Upon running make
,though, I get errors such as undefined reference to 'cv::String::deallocate()'
I am looking at other links such as Undefined reference to `cv::String::deallocate()' error in OpenCV 3.4.3 and What is an undefined reference/unresolved external symbol error and how do I fix it?, but that’s confusing me a bit more. How do I go about setting the dependency mentioned in the 1st link?
EDIT: Following this the last part of the output of the make command, which is were I get errors:
The part of my Makefile
handling opencv has the OPENCV_CFLAGS
and OPENCV_LIBS
flags. Here is a part of the Makefile
:-
# Makefile.in generated by automake 1.15.1 from Makefile.am.
# Makefile. Generated from Makefile.in by configure.
# Copyright (C) 1994-2017 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
am__is_gnu_make = {
if test -z '$(MAKELEVEL)'; then
false;
elif test -n '$(MAKE_HOST)'; then
true;
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then
true;
else
false;
fi;
}
am__make_running_with_option =
case $${target_option-} in
?) ;;
*) echo "am__make_running_with_option: internal error: invalid"
"target option '$${target_option-}' specified" >&2;
exit 1;;
esac;
has_opt=no;
sane_makeflags=$$MAKEFLAGS;
if $(am__is_gnu_make); then
sane_makeflags=$$MFLAGS;
else
case $$MAKEFLAGS in
*[ ]*)
bs=;
sane_makeflags=`printf '%sn' "$$MAKEFLAGS"
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;;
esac;
fi;
skip_next=no;
strip_trailopt ()
{
flg=`printf '%sn' "$$flg" | sed "s/$$1.*$$//"`;
};
for flg in $$sane_makeflags; do
test $$skip_next = yes && { skip_next=no; continue; };
case $$flg in
*=*|--*) continue;;
-*I) strip_trailopt 'I'; skip_next=yes;;
-*I?*) strip_trailopt 'I';;
-*O) strip_trailopt 'O'; skip_next=yes;;
-*O?*) strip_trailopt 'O';;
-*l) strip_trailopt 'l'; skip_next=yes;;
-*l?*) strip_trailopt 'l';;
-[dEDm]) skip_next=yes;;
-[JT]) skip_next=yes;;
esac;
case $$flg in
*$$target_option*) has_opt=yes; break;;
esac;
done;
test $$has_opt = yes
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/libxcam
pkgincludedir = $(includedir)/libxcam
pkglibdir = $(libdir)/libxcam
pkglibexecdir = $(libexecdir)/libxcam
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = x86_64-pc-linux-gnu
host_triplet = x86_64-pc-linux-gnu
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4
$(top_srcdir)/m4/xcam-utils.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES)
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure
$(am__configure_deps) $(am__DIST_COMMON)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log
configure.lineno config.status.lineno
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_$(V))
am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY))
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_$(V))
am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
am__v_GEN_0 = @echo " GEN " $@;
am__v_GEN_1 =
AM_V_at = $(am__v_at_$(V))
am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
am__v_at_0 = @
am__v_at_1 =
SOURCES =
DIST_SOURCES =
RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive
ctags-recursive dvi-recursive html-recursive info-recursive
install-data-recursive install-dvi-recursive
install-exec-recursive install-html-recursive
install-info-recursive install-pdf-recursive
install-ps-recursive install-recursive installcheck-recursive
installdirs-recursive pdf-recursive ps-recursive
tags-recursive uninstall-recursive
am__can_run_installinfo =
case $$AM_UPDATE_INFO_DIR in
n|no|NO) false;;
*) (install-info --version) >/dev/null 2>&1;;
esac
RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive
distclean-recursive maintainer-clean-recursive
am__recursive_targets =
$(RECURSIVE_TARGETS)
$(RECURSIVE_CLEAN_TARGETS)
$(am__extra_recursive_targets)
AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS
cscope distdir dist dist-all distcheck
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES)
$(LISP)config.h.in
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
am__uniquify_input = $(AWK) '
BEGIN { nonempty = 0; }
{ items[$$0] = 1; nonempty = 1; }
END { if (nonempty) { for (i in items) print i; }; }
'
# Make sure the list of sources is unique. This is necessary because,
# e.g., the same source file might be shared among _SOURCES variables
# for different programs/libraries.
am__define_uniq_tagged_files =
list='$(am__tagged_files)';
unique=`for i in $$list; do
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi;
done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
CSCOPE = cscope
DIST_SUBDIRS = xcore shaders modules plugins wrapper capi tests
pkgconfig
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in AUTHORS
COPYING ChangeLog NEWS compile config.guess config.sub
install-sh ltmain.sh missing
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
am__remove_distdir =
if test -d "$(distdir)"; then
find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';'
&& rm -rf "$(distdir)"
|| { sleep 5 && rm -rf "$(distdir)"; };
else :; fi
am__post_remove_distdir = $(am__remove_distdir)
am__relativize =
dir0=`pwd`;
sed_first='s,^([^/]*)/.*$$,1,';
sed_rest='s,^[^/]*/*,,';
sed_last='s,^.*/([^/]*)$$,1,';
sed_butlast='s,/*[^/]*$$,,';
while test -n "$$dir1"; do
first=`echo "$$dir1" | sed -e "$$sed_first"`;
if test "$$first" != "."; then
if test "$$first" = ".."; then
dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2";
dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`;
else
first2=`echo "$$dir2" | sed -e "$$sed_first"`;
if test "$$first2" = "$$first"; then
dir2=`echo "$$dir2" | sed -e "$$sed_rest"`;
else
dir2="../$$dir2";
fi;
dir0="$$dir0"/"$$first";
fi;
fi;
dir1=`echo "$$dir1" | sed -e "$$sed_rest"`;
done;
reldir="$$dir2"
DIST_ARCHIVES = $(distdir).tar.gz
GZIP_ENV = --best
DIST_TARGETS = dist-gzip
distuninstallcheck_listfiles = find . -type f -print
am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles)
| sed 's|^./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
distcleancheck_listfiles = find . -type f -print
ACLOCAL = ${SHELL} /media/ubuntu/apps1/mvision/tech/SVS3D/libxcam_test/missing aclocal-1.15
AMTAR = $${TAR-tar}
AM_DEFAULT_VERBOSITY = 1
AR = ar
AUTOCONF = ${SHELL} /media/ubuntu/apps1/mvision/tech/SVS3D/libxcam_test/missing autoconf
AUTOHEADER = ${SHELL} /media/ubuntu/apps1/mvision/tech/SVS3D/libxcam_test/missing autoheader
AUTOMAKE = ${SHELL} /media/ubuntu/apps1/mvision/tech/SVS3D/libxcam_test/missing automake-1.15
AWK = gawk
CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
CPP = gcc -E
CPPFLAGS =
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=gcc3
CXXFLAGS = -g -O2
CYGPATH_W = echo
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
DLLTOOL = false
DOXYGEN =
DSYMUTIL =
DUMPBIN =
ECHO_C =
ECHO_N = -n
ECHO_T =
EGREP = /bin/grep -E
EXEEXT =
FGREP = /bin/grep -F
GAWK = gawk
GREP = /bin/grep
GST_ALLOCATOR_CFLAGS = -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
GST_ALLOCATOR_LIBS = -lgstallocators-1.0 -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0
GST_CFLAGS = -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
GST_LIBS = -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0
GST_VIDEO_CFLAGS = -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/orc-0.4 -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
GST_VIDEO_LIBS = -lgstvideo-1.0 -lgstbase-1.0 -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0
IA_AIQ_CFLAGS =
IA_AIQ_LIBS =
IA_IMAGING_CFLAGS =
IA_IMAGING_LIBS =
INSTALL = /usr/bin/install -c
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
LD = /usr/bin/ld -m elf_x86_64
LDFLAGS =
LIBCL_CFLAGS =
LIBCL_LIBS = -lOpenCL
LIBDRM_CFLAGS = -I/usr/include/libdrm
LIBDRM_LIBS = -ldrm
LIBGBM_CFLAGS =
LIBGBM_LIBS =
LIBGL_CFLAGS = -I/usr/include/libdrm
LIBGL_LIBS = -lGL
LIBOBJS =
LIBOSG_CFLAGS =
LIBOSG_LIBS =
LIBS =
LIBTOOL = $(SHELL) $(top_builddir)/libtool
LIBVULKAN_CFLAGS =
LIBVULKAN_LIBS =
LIPO =
LN_S = ln -s
LTLIBOBJS =
LT_SYS_LIBRARY_PATH =
MAKEINFO = ${SHELL} /media/ubuntu/apps1/mvision/tech/SVS3D/libxcam_test/missing makeinfo
MANIFEST_TOOL = :
MKDIR_P = /bin/mkdir -p
NM = /usr/bin/nm -B
NMEDIT =
OBJDUMP = objdump
OBJEXT = o
OPENCV_CFLAGS = -I/usr/local/include/opencv4
OPENCV_LIBS = -L/usr/local/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_cudaoptflow -lopencv_optflow -lopencv_cudalegacy -lopencv_videoio -lopencv_cudawarping -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_dnn -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev
P.S.: I have found that allocate() and deallocate() have been declared in cvstd.hpp and I see definitions for them in the same file. But I’m not sure why the linker can’t find it.
Also, my Makefile has dependencies such as -lopencv_core -lopencv_highgui -lopencv_imgproc
are already set. I don’t why I’m still getting a link error.
P.P.S.: I am new to C++, so much of the code compilation process is unfamiliar to me. Any help would be much appreciated.
2
Answers
I fixed the error. Thanks @Scheff'sCat for the comments. The only version of opencv that I have on my system is opencv 4.5.2.
I'm not sure how helpful my answer will be to everybody because the problem was more system specific. I use a communal Desktop at work, and the folder structure is a bit strange based on how other users have installed packages and moved folders around.
/usr/local/include/opencv4/opencv2
contains all the files needed by the repo I'm trying to build. But the make command accesses/usr/include/opencv2
which doesn't contain few of the files needed by the repo. I just had to move the contents of/usr/local/include/opencv4/opencv2
to/usr/include/opencv2
and themake
worked.To build and run C++ code that uses OpenCV C++, you need to install the OpenCV C++ library and set up dependencies. While OpenCV Python is a wrapper around the C++ library, it doesn’t include the necessary dependencies for C++ code. Therefore, installing OpenCV Python alone won’t work.
If you encounter errors during the build process, such as "undefined reference to ‘cv::String::deallocate()’", it indicates a linking issue with the OpenCV C++ library. To resolve this issue, you need to link the library correctly to your C++ project during the build process.
In summary, to build and run C++ code that uses OpenCV C++, you need to install the OpenCV C++ library and correctly set up dependencies. OpenCV Python isn’t sufficient for building C++ code, so it’s important to follow the correct installation and setup steps to avoid errors.