链接OpenCV库的顺序是什么?

时间:2013-11-04 11:30:39

标签: android c++ opencv java-native-interface

我正在使用OpenCV库来实现VLC应用程序的模块。

我想使用函数cvSaveImage,但是我收到很多错误:

/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&):grfmt_jpeg.cpp(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x22c): error: undefined reference to 'jpeg_stdio_dest'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&):grfmt_jpeg.cpp(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x26e): error: undefined reference to 'jpeg_write_scanlines'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&):grfmt_jpeg.cpp(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x2bc): error: undefined reference to 'jpeg_write_scanlines'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::my_jpeg_load_dht(jpeg_decompress_struct*, unsigned char*, JHUFF_TBL**, JHUFF_TBL**) [clone .constprop.36]:grfmt_jpeg.cpp(.text.unlikely._ZN2cvL16my_jpeg_load_dhtEP22jpeg_decompress_structPhPP9JHUFF_TBLS5_.constprop.36+0x94): error: undefined reference to 'jpeg_alloc_huff_table'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegDecoder::close():grfmt_jpeg.cpp(.text._ZN2cv11JpegDecoder5closeEv+0xa): error: undefined reference to 'jpeg_destroy_decompress'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegDecoder::readData(cv::Mat&):grfmt_jpeg.cpp(.text._ZN2cv11JpegDecoder8readDataERNS_3MatE+0x82): error: undefined reference to 'jpeg_start_decompress'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegDecoder::readData(cv::Mat&):grfmt_jpeg.cpp(.text._ZN2cv11JpegDecoder8readDataERNS_3MatE+0xf2): error: undefined reference to 'jpeg_read_scanlines'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegDecoder::readData(cv::Mat&):grfmt_jpeg.cpp(.text._ZN2cv11JpegDecoder8readDataERNS_3MatE+0x136): error: undefined reference to 'jpeg_finish_decompress'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegDecoder::readHeader():grfmt_jpeg.cpp(.text._ZN2cv11JpegDecoder10readHeaderEv+0x1e): error: undefined reference to 'jpeg_std_error'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegDecoder::readHeader():grfmt_jpeg.cpp(.text._ZN2cv11JpegDecoder10readHeaderEv+0x52): error: undefined reference to 'jpeg_CreateDecompress'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegDecoder::readHeader():grfmt_jpeg.cpp(.text._ZN2cv11JpegDecoder10readHeaderEv+0x92): error: undefined reference to 'jpeg_stdio_src'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegDecoder::readHeader():grfmt_jpeg.cpp(.text._ZN2cv11JpegDecoder10readHeaderEv+0xa2): error: undefined reference to 'jpeg_read_header'
/home/virginia/workspace/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a//libopencv_highgui.a(grfmt_jpeg.cpp.o): in function cv::JpegDecoder::readHeader():grfmt_jpeg.cpp(.text._ZN2cv11JpegDecoder10readHeaderEv+0x14c): error: undefined reference to 'jpeg_resync_to_restart'

我必须在Android.mk文件的名为LOCAL_LDLIBS的变量中链接OpenCV库。

LOCAL_LDLIBS := -L$(VLC_CONTRIB)/lib \
    -L/home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/ \
    -L/home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/libs/armeabi-v7a/ \
-ltbb -lopencv_core -lopencv_contrib -lopencv_legacy -lopencv_videostab -lopencv_photo -lopencv_stitching -lopencv_objdetect -lopencv_video -lopencv_ml -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_flann -lopencv_imgproc -lopencv_core -ltbb

我认为我必须链接/home/virginia/workspace/OpenCV-2.4.5-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/中的库: libIlmImf.a liblibjasper.a liblibjpeg.a liblibpng.a liblibtiff.a

但我不知道链接它们的顺序。

拜托,我需要任何帮助! 非常感谢!

2 个答案:

答案 0 :(得分:0)

我相信提供的链接here给出了答案;具体来说,请查看Native C / C ++部分的#4 部分..

希望这有帮助。

答案 1 :(得分:0)

对于那些使用CMake的人来说,这可能看起来很愚蠢,但对于我们这些使用make的人来说,因为我们没有使用它,这很有用。

找到opencv.pc文件的路径并调用pkg-config,然后输出所需的所有内容到g ++ / clang ++的调用中。如上所述,你也可以只调用pkg-config二进制文件并将其传递给opencv.pc文件,然后你就有了库顺序,但当然最好直接使用opencv.pc文件。

例如,在我的makefile中:

OPENCVINCPKG=$(OPENCVLIBPATH)/pkgconfig/opencv.pc
g++ `pkg-config --cflags --libs $(OPENCVINCPKG)` myClient.cpp -o myClient

希望这对某人有所帮助,感谢ChronoTrigger让我来到这里。