环境:Debian 7.5 Wheezy。
我刚刚编译并安装了OpenCV库,版本2.4.9,激活了Intel IPP(Integrated Performance Primitives)。我在/ opt / ipp,版本8.1 SP 3中安装了IPP。
在cmake期间,它会找到OK IPP库,并在/ opt / OpenCV中编译和安装没有问题。
当我转到c示例文件夹时,会有一个编译所有示例的脚本:
$ ls /opt/OpenCV/OpenCV-2.4.9/share/OpenCV/samples/c
adaptiveskindetector.cpp box_in_scene.png facedetect.cmd latentsvmdetect.cpp one_way_train_0001.jpg
agaricus-lepiota.data box.png facedetect.cpp lena.jpg polar_transforms.c
airplane.jpg build_all.sh fback_c.c morphology.c puzzle.png
baboon200.jpg cat.jpg find_obj_calonder.cpp motempl.c pyramid_segmentation.c
baboon200_rotated.jpg contours.c find_obj.cpp mser_sample.cpp smiledetect.cpp
baboon.jpg convert_cascade.c find_obj_ferns.cpp mushroom.cpp stuff.jpg
bgfg_codebook.cpp cvsample.dsp fruits.jpg one_way_sample.cpp tree_engine.cpp
blobtrack_sample.cpp delaunay.c JCB.png one_way_train_0000.jpg waveform.data
现在,让我们运行脚本:
$ ./build_all.sh
每个源文件都提供如下输出:
compiling tree_engine.cpp
/usr/bin/ld: cannot find -llibsvml.so
/usr/bin/ld: cannot find -llibimf.so
/usr/bin/ld: cannot find -llibirc.so
/usr/bin/ld: cannot find -llibippcore.a
/usr/bin/ld: cannot find -llibipps.a
/usr/bin/ld: cannot find -llibippi.a
/usr/bin/ld: cannot find -llibippcv.a
/usr/bin/ld: cannot find -llibippcc.a
/usr/bin/ld: cannot find -llibippvm.a
collect2: error: ld returned 1
build_all.sh的内容:
#!/bin/sh
if [ $# -gt 0 ] ; then
base=`basename $1 .c`
echo "compiling $base"
gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base
else
for i in *.c; do
echo "compiling $i"
gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv`;
done
for i in *.cpp; do
echo "compiling $i"
g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config --libs opencv`;
done
fi
让我们关注第一个找不到的库(/ usr / bin / ld:找不到-llibsvml.so)。
它在系统中: $ locate libsvml.so /opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/ia32/libsvml.so /opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64/libsvml.so /opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/mic/libsvml.so
其文件夹位于LD_LIBRARY_PATH:
中$ echo $LD_LIBRARY_PATH
/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64:/opt/intel/composer_xe_2013_sp1.3.174/mpirt/lib/intel64:/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64:/opt/intel/composer_xe_2013_sp1.3.174/ipp/lib/intel64:/opt/OpenCV/OpenCV-2.4.9/lib
在LIBRARY_PATH中:
$ echo $LIBRARY_PATH
/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64:/opt/intel/composer_xe_2013_sp1.3.174/ipp/lib/intel64
据我所知,buildAll脚本依赖于pkg-config来查找库。值得注意的是,这些命令在运行时不返回任何内容:
$ pkg-config --list-all | grep ipp
$ pkg-config --list-all | grep vml
$ dpkg -l | grep ipp
$ dpkg -l | grep vml
gcc在编译期间在哪里查看:
$ gcc --print-search-dirs
install: /usr/lib/gcc/x86_64-linux-gnu/4.7/
programs: =/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/bin/
libraries: =/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64/x86_64-linux-gnu/4.7/:/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64/x86_64-linux-gnu/:/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64/../lib/:/opt/intel/composer_xe_2013_sp1.3.174/ipp/lib/intel64/x86_64-linux-gnu/4.7/:/opt/intel/composer_xe_2013_sp1.3.174/ipp/lib/intel64/x86_64-linux-gnu/:/opt/intel/composer_xe_2013_sp1.3.174/ipp/lib/intel64/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib/:/lib/x86_64-linux-gnu/4.7/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/4.7/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64/:/opt/intel/composer_xe_2013_sp1.3.174/ipp/lib/intel64/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../:/lib/:/usr/lib/
我如何编译它,所以gcc找到IPP库?
编辑1
我尝试创建文件/etc/ld.so.conf.d/IntelIPP.conf并在其中添加LD_LIBRARY_PATH中设置的Intel IPP路径,重新启动系统并重新编译。没效果。
但是,我猜这个:" / usr / bin / ld:找不到-llibsvml.so" 应该意味着它正在寻找对于" liblibsvml.so" (我认为ld足以满足" lib"在库文件名内部)。
需要注意的另一点:" gcc -ggdb pkg-config --cflags opencv
-o basename $i .c
$ i`pkg-config --libs" 执行pkg-config仅针对opencv,根本没有命名IPP。因此,它可能是一些在编译或安装过程中由OpenCV硬编码的lib位置。
关于此的任何线索?
编辑2
按照这种新方法,我已经去了〜/ Downloads / openscv-2.4.9 / cmake / OpenCVFindIPP.cmake并更改了:
# ------------------------------------------------------------------------
# This is auxiliary function called from set_ipp_variables()
# to set IPP_LIBRARIES variable in IPP 7.x and 8.x style
# ------------------------------------------------------------------------
function(set_ipp_new_libraries _LATEST_VERSION)
set(IPP_PREFIX "ipp")
if(${_LATEST_VERSION} VERSION_LESS "8.0")
set(IPP_SUFFIX "_l") # static not threaded libs suffix IPP 7.x
else()
if(WIN32)
set(IPP_SUFFIX "mt") # static not threaded libs suffix IPP 8.x for Windows
else()
set(IPP_SUFFIX "") # static not threaded libs suffix IPP 8.x for Linux/OS X
endif()
endif()
set(IPPCORE "core") # core functionality
set(IPPSP "s") # signal processing
set(IPPIP "i") # image processing
set(IPPCC "cc") # color conversion
set(IPPCV "cv") # computer vision
set(IPPVM "vm") # vector math
set(IPP_LIBRARIES
${IPP_PREFIX}${IPPVM}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_PREFIX}${IPPCC}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_PREFIX}${IPPCV}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_PREFIX}${IPPI}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_PREFIX}${IPPS}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_PREFIX}${IPPCORE}${IPP_SUFFIX}${IPP_LIB_SUFFIX})
if (UNIX)
set(IPP_LIBRARIES
${IPP_LIBRARIES}
irc${CMAKE_SHARED_LIBRARY_SUFFIX}
imf${CMAKE_SHARED_LIBRARY_SUFFIX}
svml${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
set(IPP_LIBRARIES ${IPP_LIBRARIES} PARENT_SCOPE)
return()
endfunction()
由:
# ------------------------------------------------------------------------
# This is auxiliary function called from set_ipp_variables()
# to set IPP_LIBRARIES variable in IPP 7.x and 8.x style
# ------------------------------------------------------------------------
function(set_ipp_new_libraries _LATEST_VERSION)
set(IPP_PREFIX "ipp")
if(${_LATEST_VERSION} VERSION_LESS "8.0")
set(IPP_SUFFIX "_l") # static not threaded libs suffix IPP 7.x
else()
if(WIN32)
set(IPP_SUFFIX "mt") # static not threaded libs suffix IPP 8.x for Windows
else()
set(IPP_SUFFIX "") # static not threaded libs suffix IPP 8.x for Linux/OS X
endif()
endif()
set(IPPCORE "core") # core functionality
set(IPPSP "s") # signal processing
set(IPPIP "i") # image processing
set(IPPCC "cc") # color conversion
set(IPPCV "cv") # computer vision
set(IPPVM "vm") # vector math
set(IPP_LIBRARIES
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPVM}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCC}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCV}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPI}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPS}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCORE}${IPP_SUFFIX}${IPP_LIB_SUFFIX})
if (UNIX)
set(IPP_LIBRARIES
${IPP_LIBRARIES}
${IPP_LIB_PREFIX}irc${CMAKE_SHARED_LIBRARY_SUFFIX}
${IPP_LIB_PREFIX}imf${CMAKE_SHARED_LIBRARY_SUFFIX}
${IPP_LIB_PREFIX}svml${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
set(IPP_LIBRARIES ${IPP_LIBRARIES} PARENT_SCOPE)
return()
endfunction()
重新编译OpenCV并成功安装......没有运气。编译示例现在提供相同的错误,但没有" lib":
compiling tree_engine.cpp
/usr/bin/ld: cannot find -lsvml.so
/usr/bin/ld: cannot find -limf.so
/usr/bin/ld: cannot find -lirc.so
/usr/bin/ld: cannot find -lippcore.a
/usr/bin/ld: cannot find -lipps.a
/usr/bin/ld: cannot find -lippi.a
/usr/bin/ld: cannot find -lippcv.a
/usr/bin/ld: cannot find -lippcc.a
/usr/bin/ld: cannot find -lippvm.a
collect2: error: ld returned 1 exit status
编辑3
另一种方法:搜索" svml"在/opt/OpenCV/OpenCV-2.4.9 /.
这导致2个文件。
/opt/OpenCV/OpenCV-2.4.9/share/OpenCV/OpenCVModules-debug.cmake:
# Import target "opencv_ts" for configuration "Debug"
SET_PROPERTY(TARGET opencv_ts APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
SET_TARGET_PROPERTIES(opencv_ts PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG "opencv_core;opencv_flann;opencv_imgproc;opencv_highgui;opencv_features2d;dl;m;pthread;rt;/usr/lib/x86_64-linux-gnu/libGLU.so;/usr/lib/x86_64-linux-gnu/libGL.so;/usr/lib/x86_64-linux-gnu/libSM.so;/usr/lib/x86_64-linux-gnu/libICE.so;/usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so;tbb;libippvm.a;libippcc.a;libippcv.a;libippi.a;libipps.a;libippcore.a;libirc.so;libimf.so;libsvml.so"
IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/lib/libopencv_ts.a"
)
LIST(APPEND _IMPORT_CHECK_TARGETS opencv_ts )
LIST(APPEND _IMPORT_CHECK_FILES_FOR_opencv_ts "${_IMPORT_PREFIX}/lib/libopencv_ts.a" )
仅显示第211至220行。不确定这些行的真正含义。
/opt/OpenCV/OpenCV-2.4.9/lib/pkgconfig/opencv.pc
# Package Information for pkg-config
prefix=/opt/OpenCV/OpenCV-2.4.9
exec_prefix=${prefix}
libdir=
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.4.9
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_ocl.so ${exec_prefix}/lib/libopencv_photo.so ${exec_prefix}/lib/libopencv_stitching.so ${exec_prefix}/lib/libopencv_superres.so ${exec_prefix}/lib/libopencv_ts.a ${exec_prefix}/lib/libopencv_video.so ${exec_prefix}/lib/libopencv_videostab.so ${exec_prefix}/lib/libopencv_viz.so -llibsvml.so -llibimf.so -llibirc.so -llibippcore.a -llibipps.a -llibippi.a -llibippcv.a -llibippcc.a -llibippvm.a -ltbb /usr/lib/x86_64-linux-gnu/libXext.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so -lrt -lpthread -lm -ldl
Cflags: -I${includedir_old} -I${includedir_new}
我认为这个文件非常有趣,据我所知,它是pkg-config和ld在链接和编译时加载库所使用的文件。
请注意:
Libs:(...)$ {exec_prefix} /lib/libopencv_viz.so -llibsvml.so -llibimf.so -llibirc.so -llibippcore.a -llibipps.a -llibippi.a -llibippcv。 a -llibippcc.a -llibippvm.a -ltbb /usr/lib/x86_64-linux-gnu/libXext.so(..)
我仍然不确定该怎么办... -l [xxx]应该从LD_LIBRARY_PATH加载xxx,所以这应该有用......任何想法?
答案 0 :(得分:2)
自己解决了。
编辑/opt/OpenCV/OpenCV-2.4.9/lib/pkgconfig/opencv.pc并将其放入:
# Package Information for pkg-config
prefix=/opt/OpenCV/OpenCV-2.4.9
exec_prefix=${prefix}
libdir=
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include
#RLP 16-06-14: For Intel IPP 8.1
IntelIPPCompilerLib=/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64
IntelIPPIPPLib=/opt/intel/composer_xe_2013_sp1.3.174/ipp/lib/intel64
#RLP'end
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.4.9
#RLP 16-06-14: For Intel IPP 8.1
#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_ocl.so ${exec_prefix}/lib/libopencv_photo.so ${exec_prefix}/lib/libopencv_stitching.so ${exec_prefix}/lib/libopencv_superres.so ${exec_prefix}/lib/libopencv_ts.a ${exec_prefix}/lib/libopencv_video.so ${exec_prefix}/lib/libopencv_videostab.so ${exec_prefix}/lib/libopencv_viz.so -llibsvml.so -llibimf.so -llibirc.so -llibippcore.a -llibipps.a -llibippi.a -llibippcv.a -llibippcc.a -llibippvm.a -ltbb /usr/lib/x86_64-linux-gnu/libXext.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so -lrt -lpthread -lm -ldl
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_ocl.so ${exec_prefix}/lib/libopencv_photo.so ${exec_prefix}/lib/libopencv_stitching.so ${exec_prefix}/lib/libopencv_superres.so ${exec_prefix}/lib/libopencv_ts.a ${exec_prefix}/lib/libopencv_video.so ${exec_prefix}/lib/libopencv_videostab.so ${exec_prefix}/lib/libopencv_viz.so ${IntelIPPCompilerLib}/libsvml.so ${IntelIPPCompilerLib}/libimf.so ${IntelIPPCompilerLib}/libirc.so ${IntelIPPIPPLib}/libippcore.a ${IntelIPPIPPLib}/libipps.a ${IntelIPPIPPLib}/libippi.a ${IntelIPPIPPLib}/libippcv.a ${IntelIPPIPPLib}/libippcc.a ${IntelIPPIPPLib}/libippvm.a -ltbb /usr/lib/x86_64-linux-gnu/libXext.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so -lrt -lpthread -lm -ldl
#RLP'end
Cflags: -I${includedir_old} -I${includedir_new}
现在系统没有抱怨这个库。
让我感到惊讶的是,在Libs部分,我尝试使用几种风格-L + -l的组合但没有成功。 (例如:-L / opt / intel / composer_xe_2013_sp1.3.174 / compiler / lib / intel64 -llibsmvl.so(和-svml))。
所以我决定直接将文件夹路径放到IPP库中。