1

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

我想使用函数 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

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

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

4

2 回答 2

0

我相信此处提供的链接可以为您提供答案;具体来说,请查看本机 C/C++ 部分的第 4点。

希望这可以帮助。

于 2013-11-04T20:02:24.370 回答
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 让我来到这里。

于 2015-12-29T00:20:46.973 回答