簡體   English   中英

gstreamer插件庫未鏈接到opencv共享對象庫-Ubuntu上的“未定義符號”

[英]gstreamer plugin library not linking against opencv shared object library - “undefined symbol” on Ubuntu

我已經嘗試了整個周末-周六/周日和周一花費了幾個小時,但無濟於事。 我正在遵循gstreamer插件編寫者指南http://gstreamer.freedesktop.org/data/doc/gstreamer/head/pwg/html/section-boiler-project-stamp.html 在嘗試gstreamer插件過程之前,我已經安裝了gstreamer-0.10(sudo apt-get安裝方法)和OpenCV 2.4。 我正在使用默認前綴( /usr/local/lib/gstreamer-0.10./configure進行sudo make && sudo make install之前的插件測試中)

我設法生成樣板代碼。 現在我添加了一個cvcreateImage

static GstFlowReturn
gst_cvtestfilter_chain (GstPad * pad, GstBuffer * buf)
{
Gstcvtestfilter *filter;
GstBuffer *outbuf;
IplImage* cvImage = cvCreateImage(cvSize(cvwidth,cvheight),cvdepth, cvchannels);
.
.
}

如果對cvImage行進行了注釋,那么一切將順利進行。 所有測試都可以。 如果我不對此行發表評論,則由於某種原因,無法鏈接到OpenCV。

我修改了makefile.am以在src目錄中添加OpenCV標志為

 # Note: plugindir is set in configure

##############################################################################
# TODO: change libgstcvtestfilter.la to something else, e.g. libmysomething.la     #
##############################################################################
plugin_LTLIBRARIES = libgstcvtestfilter.la

##############################################################################
# TODO: for the next set of variables, name the prefix if you named the .la, #
#  e.g. libmysomething.la => libmysomething_la_SOURCES                       #
#                            libmysomething_la_CFLAGS                        #
#                            libmysomething_la_LIBADD                        #
#                            libmysomething_la_LDFLAGS                       #
##############################################################################

# sources used to compile this plug-in
libgstcvtestfilter_la_SOURCES = gstcvtestfilter.c gstcvtestfilter.h

# compiler and linker flags used to compile this plugin, set in configure.ac
libgstcvtestfilter_la_CFLAGS = $(GST_CFLAGS) $(OPENCV_CFLAGS)
libgstcvtestfilter_la_LIBADD = $(GST_LIBS) $(OPENCV_LIBS)
libgstcvtestfilter_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) 
libgstcvtestfilter_la_LIBTOOLFLAGS = --tag=disable-static

# headers we need but don't want installed
noinst_HEADERS = gstcvtestfilter.h

我還通過添加在父目錄中修改了configure.ac

 dnl *** opencv ***
translit(dnm, m, l) AM_CONDITIONAL(USE_OPENCV, true)

  dnl we specify a max. version too because we set CV_NO_BACKWARD_COMPATIBILITY
  dnl and don't want the build to break when a new opencv version comes out.
  dnl Need to adjust this upwards once we know that our code compiles fine with
  dnl a new version and the no-backward-compatibility define. (There doesn't
  dnl seem to be a switch to suppress the warnings the cvcompat.h header
  dnl causes.)
  PKG_CHECK_MODULES(OPENCV, opencv >= 2.0.0 opencv <= 3.1.0 , [
    AC_PROG_CXX
    AC_LANG_CPLUSPLUS
    OLD_CPPFLAGS=$CPPFLAGS
    CPPFLAGS=$OPENCV_CFLAGS
    AC_CHECK_HEADER(highgui.h, HAVE_HIGHGUI="yes", HAVE_HIGHGUI="no")
    AC_CHECK_HEADER(cvaux.h, HAVE_CVAUX="yes", HAVE_CVAUX="no")
    CPPFLAGS=$OLD_CPPFLAGS
    AC_LANG_C
    if test "x$HAVE_HIGHGUI" = "xno"; then
      AC_MSG_RESULT(highgui.h could not be found.)
      HAVE_OPENCV="no"
    elif test "x$HAVE_CVAUX" = "xno"; then
      AC_MSG_RESULT(cvaux.h could not be found.)
      HAVE_OPENCV="no"
    else
      HAVE_OPENCV="yes" 
      AC_SUBST(OPENCV_CFLAGS)
      AC_SUBST(OPENCV_LIBS)  
    fi
  ], [
    HAVE_OPENCV="no"
    AC_MSG_RESULT(no)
  ])

編譯很好-沒有錯誤。

現在,當我在管道中運行插件時,會收到此消息

(gst-plugin-scanner:6396): GStreamer-WARNING **: Failed to load plugin '/usr/local/lib/gstreamer-0.10/libgstcvtestfilter.so': /usr/local/lib/gstreamer-0.10/libgstcvtestfilter.so: undefined symbol: cvCreateImage

所以很明顯,我位於/usr/local/lib opencv沒有正確鏈接。

sudo gedit /etc/bash.bashrc包含

#Added By me
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

#Added By me
PATH=$PATH:/opt/Xilinx/13.4/ISE_DS/ISE/bin/lin
export PATH

GST_PLUGIN_PATH=$GST_PLUGIN_PATH:/usr/local/lib/gstreamer-0.10
export GST_PLUGIN_PATH

sudo gedit /etc/ld.so.conf.d/opencv.conf包含

/usr/local/lib

sudo gedit /etc/ld.so.conf.d/gst.conf包含

/usr/local/lib/gstreamer-0.10

sudo ldconfig -v

sudo gedit ~/.bashrc包含

export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/gstreamer-0.10

ldd /usr/local/lib/gstreamer-0.10/libgstcvtestfilter.so沒有提供opencv依賴關系,這很奇怪

linux-gate.so.1 =>  (0xb77b6000)
libgstreamer-0.10.so.0 => /usr/lib/i386-linux-gnu/libgstreamer-0.10.so.0 (0xb76b0000)
libgobject-2.0.so.0 => /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 (0xb7661000)
libglib-2.0.so.0 => /lib/i386-linux-gnu/libglib-2.0.so.0 (0xb7567000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb754c000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb73a7000)
libgmodule-2.0.so.0 => /usr/lib/i386-linux-gnu/libgmodule-2.0.so.0 (0xb73a2000)
libxml2.so.2 => /usr/lib/i386-linux-gnu/libxml2.so.2 (0xb7255000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7228000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb721f000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb721a000)
libffi.so.6 => /usr/lib/i386-linux-gnu/libffi.so.6 (0xb7213000)
libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3 (0xb71d7000)
/lib/ld-linux.so.2 (0xb77b7000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb71c0000)

我的操作系統是32位12.04 Ubuntu。 如果有人能指出正確的方向,我將不勝感激。 謝謝。

更新:(2012年6月29日)

從OpenCV經驗中獲取Cue,如果有人感興趣,我為OpenGL修改了configure.ac

AC_CHECK_HEADER(
    GL/gl.h,
    AC_DEFINE(
        [HAVE_OPENGL],
        [],
        Define to 1 if you have the <GL/gl.h> header file.
        )
        OPENGL_LIBS="$X_LIBS -lGL -lGLU -lpthread -lglut -lGLEW"
        opengl=yes,
    AC_MSG_WARN([*** no GL/gl.h -- opengl and SDL support disabled])
)
AC_SUBST(OPENGL_CFLAGS)
AC_SUBST(OPENGL_LIBS)


dnl AC_ARG_WITH(
dnl     opengl-cflags,
dnl     [  --with-opengl-cflags=PATH    Specify OpenGL cflags],
dnl     OPENGL_CFLAGS="$withval", OPENGL_CFLAGS="")
dnl AC_ARG_WITH(
dnl     opengl-libs,
dnl     [  --with-opengl-libs=PATH      Specify OpenGL libs (default is -lGL -lGLU -lpthread)],
dnl     OPENGL_LIBS="$withval", OPENGL_LIBS="-lGL -lGLU -lpthread -lglut -lGLEW")
dnl AC_SUBST(OPENGL_CFLAGS)
dnl AC_SUBST(OPENGL_LIBS)

我知道這個問題與GStreamer的0.1版本有關,但是在從源代碼進行編譯時,GStreamer v1.4.5以及從源代碼進行編譯的OpenCV 2.4.10.1也遇到了類似的錯誤。

就我而言,運行gst-inspect-1.0將顯示以下消息:

(gst-plugin-scanner:7485): GStreamer-WARNING **: Failed to load plugin '/usr/local/lib/gstreamer-1.0/libgstopencv.so': /usr/local/lib/gstreamer-1.0/libgstopencv.so: undefined symbol: cvCloneImage
...
...
Total count: 196 plugins (1 blacklist entry not shown), 1109 features

我的解決方案從此處的解決方案2中得到啟發,但是無需更改源文件,只需將OPENCV_LIBS環境變量傳遞給autogen.sh。

OPENCV_LIBS="-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_nonfree -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_videostab" ./autogen.sh

您可能需要根據所使用的構建配置來調整庫。

這是我從pkg-config --libs opencv輸出:

/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so -lrt -lpthread -lm -ldl

我設法解決了這個問題,並通過src目錄中Makefile中的一個難看的hack咨詢了一位朋友。

解決方案一

LIBS =為空,因此必須在其中添加OpenCV庫,如下所示。

LDFLAGS =
LIBOBJS =
LIBS = -lopencv_core -lopencv_highgui # One may add more OpenCV libraries as needed here
LIBTOOL = $(SHELL) $(top_builddir)/libtool

解決方案II(更好的解決方案出現-但仍然很丑)

保留LIBS =空,但在Makefile編輯OPENCV_LIBS=

就我而言

OPENCV_LIBS = /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_core.so ...

我用這行代替

OPENCV_LIBS = -lopencv_highgui -lopencv_core ...依此類推。

在此行中根據需要在Makefile中將其替換為所有OpenCV庫,它應該可以工作。

解決方案III(首選)如下更改Makefile.am ,並根據需要添加所有OpenCV庫。

 # Note: plugindir is set in configure

##############################################################################
# TODO: change libgstcvtestfilter.la to something else, e.g. libmysomething.la     #
##############################################################################
plugin_LTLIBRARIES = libgstcvtestfilter.la

##############################################################################
# TODO: for the next set of variables, name the prefix if you named the .la, #
#  e.g. libmysomething.la => libmysomething_la_SOURCES                       #
#                            libmysomething_la_CFLAGS                        #
#                            libmysomething_la_LIBADD                        #
#                            libmysomething_la_LDFLAGS                       #
##############################################################################

# sources used to compile this plug-in
libgstcvtestfilter_la_SOURCES = gstcvtestfilter.c gstcvtestfilter.h

# compiler and linker flags used to compile this plugin, set in configure.ac
libgstcvtestfilter_la_CFLAGS = $(GST_CFLAGS) $(OPENCV_CFLAGS)
libgstcvtestfilter_la_LIBADD = $(GST_LIBS) $(OPENCV_LIBS) -lopencv_highgui -lopencv_core
libgstcvtestfilter_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) 
libgstcvtestfilter_la_LIBTOOLFLAGS = --tag=disable-static

# headers we need but don't want installed
noinst_HEADERS = gstcvtestfilter.h

/usr/local/lib/pkgconfig/opencv.pc可以看出,opencv 2.3.1和2.4.0的安裝方式有所不同。

/usr/local/lib/pkgconfig/opencv.pc文件應如下所示:(安裝了此gstreamer opencv插件的PC可以正常工作-Ubuntu 10.04)

# Package Information for pkg-config

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.3.1
Libs: -L${libdir} -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
Cflags: -I${includedir_old} -I${includedir_new}

而不是(安裝此gstreamer opencv插件的PC需要修改Makefile-Ubuntu 12.04):

# Package Information for pkg-config

prefix=/usr/local
exec_prefix=${prefix}
libdir=
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.4.0
Libs:  ${exec_prefix}/lib/libopencv_calib3d.so ${exec_prefix}/lib/libopencv_contrib.so ${exec_prefix}/lib/libopencv_core.so ${exec_prefix}/lib/libopencv_features2d.so ${exec_prefix}/lib/libopencv_flann.so ${exec_prefix}/lib/libopencv_gpu.so ${exec_prefix}/lib/libopencv_highgui.so ${exec_prefix}/lib/libopencv_imgproc.so ${exec_prefix}/lib/libopencv_legacy.so ${exec_prefix}/lib/libopencv_ml.so ${exec_prefix}/lib/libopencv_nonfree.so ${exec_prefix}/lib/libopencv_objdetect.so ${exec_prefix}/lib/libopencv_photo.so ${exec_prefix}/lib/libopencv_stitching.so ${exec_prefix}/lib/libopencv_ts.so ${exec_prefix}/lib/libopencv_video.so ${exec_prefix}/lib/libopencv_videostab.so
Cflags: -I${includedir_old} -I${includedir_new}

如果可以的話,我會發布更好的解決方案。

配置運行是否確實找到了opencv庫? 檢查config.log。 另外,您在configure.ac部分中做了什么更改? 如您所知,正確地認為生成的makefile應該擴展了這些var。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM