Ask Your Question
0

Autotools with opencv (undefined reference to cv::meanShift)

asked 2016-03-24 05:19:42 -0600

aripod gravatar image

updated 2016-03-24 07:52:20 -0600

Hello,

I'm using autotools to build a library that incorporates several custom functions that are based on opencv that I will use in another project.

So first I build this library with the following structure:

src/ (all .cpp files)
dpf-template/ (all .h files)
test/
configure.ac
Makefile.am
dpf_template.pc.in

configure.ac:

AC_PREREQ([2.69])

AC_INIT([calc_mean], [1.0])
AM_INIT_AUTOMAKE([foreign])
AM_MAINTAINER_MODE([enable])

AC_CONFIG_MACRO_DIR([m4])

# Checks for programs.
AC_PROG_CXX
AC_PROG_LIBTOOL

#PKG_CHECK_MODULES([calc_mean])

AC_OUTPUT([Makefile
    src/Makefile
    test/Makefile
    dpf_template.pc])

Makefile.am:

ACLOCAL_AMFLAGS = -I m4

AUTOMAKE_OPTIONS = foreign
SUBDIRS = src test

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = dpf_template.pc

src/Makefile.am

lib_LTLIBRARIES = libdpf_template.la

libdpf_template_la_SOURCES = \ (plus all the files in src/*.cpp and dpf-template/*.h

AM_CPPFLAGS = -I$(top_srcdir) `pkg-config --cflags opencv`
AM_CFLAGS = -g -Wall `pkg-config --cflags opencv` -I/usr/include/eigen3
AM_CXXFLAGS=`pkg-config --cflags opencv`

libdpf_templateincludedir = $(includedir)/dpf_template
libdpf_templateinclude_HEADERS = \ (plus all the files in dpf-template/*.h)

I also saw where opencv.pc is and then checked that it is in PKG_CONFIG_PATH.

With these, I run make and make install with no errors. So far so go, but when I build a simple project that includes this dpf_template.so (through .pc file) and I have only one error which is

libdpf_template.so: undefined reference to `cv::meanShift(cv::_InputArray const&, cv::Rect_<int>&, cv::TermCriteria)'
collect2: error: ld returned 1 exit status

Shouldn't I have been prompted something when I build the libdpf_template? Thanks for the help.

edit retag flag offensive close merge delete

Comments

what is the output of pkg-config --libs opencv ?

berak gravatar imageberak ( 2016-03-24 05:47:43 -0600 )edit

-L/usr/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lrt -lpthread -lm -ldl

aripod gravatar imagearipod ( 2016-03-24 06:19:34 -0600 )edit

I checked in /us/local/lib and they are all there, but as I had installed several versions (I regret that now....) I have this:

 libopencv_video.so
libopencv_video.so.2.4
libopencv_video.so.2.4.10
libopencv_video.so.2.4.12
libopencv_video.so.3.1
libopencv_video.so.3.1.0

Which is a mess and I cannot run make uninstall. Would it be safe to remove all of them and install one version (2.4.12)?

aripod gravatar imagearipod ( 2016-03-24 06:25:10 -0600 )edit

idk. your pkg-config seems to pick some 2.4 version (looking at the lib names)

berak gravatar imageberak ( 2016-03-24 06:29:30 -0600 )edit

which is what I want.....but maybe meanShift is in another library from 2.4.10 and 2.4.12 and that's causing the problem? Because all the other opencv functions work...I commented it the call to meanShift and the code compiled.

aripod gravatar imagearipod ( 2016-03-24 06:35:47 -0600 )edit

I run sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv* and re-compiled opencv2.4-12 but the problem still shows up.....undefined reference to `cv::meanShift

aripod gravatar imagearipod ( 2016-03-24 06:56:44 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-03-25 06:39:18 -0600

aripod gravatar image

Solved it by adding AM_LDFLAGS = pkg-config --libs opencv to the Makefile.am

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-03-24 05:19:42 -0600

Seen: 869 times

Last updated: Mar 24 '16