我有一个库,我试图将openCV(我认为我成功地)链接到一个大的动态库中。然后我尝试添加一个可执行文件并将所有内容链接在一起以测试库,我每次都会出现2000-3000错误
In function `________________`: undefined reference to `________`
一些例子是:
/path/to/libs/libopencv_features2d.a(matchers.cpp.o): In function `cv::FlannBasedMatcher::read(cv::FileNode const&)':
matchers.cpp:(.text._ZN2cv17FlannBasedMatcher4readERKNS_8FileNodeE+0x227): undefined reference to `cv::flann::IndexParams::setAlgorithm(int)'
/path/to/libs/libopencv_videoio.a(cap_gstreamer.cpp.o)` In function `CvCapture_GStreamer::getProperty(int) const':
cap_gstreamer.cpp:(.text._ZNK19CvCapture_GStreamer11getPropertyEi+0x8b): undefined reference to `gst_element_query_position'
/path/to/lib/libopencv_core.a(stat.cpp.o): In function `cv::norm(cv::_InputArray const&, int, cv::_InputArray const&)':
stat.cpp:(.text._ZN2cv4normERKNS_11_InputArrayEiS2_+0x1d27): undefined reference to `ippicviNorm_L1_32f_C1MR'
stat.cpp:(.text._ZN2cv4normERKNS_11_InputArrayEiS2_+0x1dab): undefined reference to `ippicviNorm_L1_8u_C1MR'
我的cmake文件运行:
project(SDK-build)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(MYLIB_SRC
file1.cpp
file2.cpp
file3.cpp
)
add_library(gesture SHARED ${MYLIB_SRC})
cmake_policy(SET CMP0015 NEW)
link_directories(./opencvlib-wgstreamer)
set(OPENCV_LIBS
libopencv_calib3d.a
libopencv_core.a
libopencv_features2d.a
libopencv_highgui.a
libopencv_imgcodecs.a
libopencv_imgproc.a
libopencv_ml.a
libopencv_objdetect.a
libopencv_photo.a
libopencv_video.a
libopencv_videoio.a
)
set(TEST_SRC
test.cpp
)
add_executable(gesture_test ${TEST_SRC})
#build library
#target_link_libraries(gesture -Wl,-whole-archive ${OPENCV_LIBS} -Wl,--no-whole-archive)
#build library with executable
target_link_libraries(gesture_test gesture -Wl,-whole-archive ${OPENCV_LIBS} -Wl,--no-whole-archive)
当我使用第一个target_link_libraries时,所有内容都构建并且make
没有执行问题,但是使用main()链接文件会导致大量混淆。任何建议我几个小时都在讨论这个问题。我还尝试了使用WITH_IPP=ON
,WITH_IPP=OFF
和WITH_GSTREAMER_ON
答案 0 :(得分:0)
您必须以正确的顺序指定库。 有关详细信息,请参阅here。
编辑我看到你正在使用-Wl-whole-archive,我认为这是解决问题的另一种方法,所以也许我错了