1
votes

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_LIBS = `pkg-config --libs opencv`
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.

1

1 Answers

0
votes

AM_LIBS is not what you think it is (only applies to binaries), and you should not use pkg-config that way.

You should use the PKG_CHECK_MODULES macro, to define OPENCV_LIBS and OPENCV_CFLAGS and reference those variables.

# in configure.ac
PKG_CHECK_MODULES([OPENCV], [opencv])

# in Makefile.am
AM_CFLAGS = -Wall
AM_CPPFLAGS = $(OPENCV_CFLAGS) -I $(top_srcdir) -I /usr/include/eigen3
libdpf_template_la_LIBADD = $(OPENCV_LIBS)

For more information on using PKG_CHECK_MODULES, I can refer you to my Autotools Mythbuster that has a full explanation of it.