1

I'm using the OpenCV libraries in the implementation of a module for VLC application.

I want to use the function cvSaveImage, but i get many errors:

/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'

I must link the OpenCV libraries in the variable named LOCAL_LDLIBS of Android.mk file.

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

I think that I have to link the libraries located in /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

But I dont't know the order to link them.

Please, I need any help! Thanks so much!

pneumatics
  • 2,836
  • 1
  • 27
  • 27
user2948033
  • 103
  • 1
  • 5
  • 13

3 Answers3

0

I believe the link presented here gives your answer; in specific, check out the point #4 for Native C/C++ section..

Hope this helps.

scap3y
  • 1,188
  • 10
  • 27
  • If you remove the *OPENCV_LIB_TYPE:=STATIC* line, then the dynamic libs will get linked by default. That's what it says on the documentation, at least. – scap3y Nov 18 '13 at 19:44
0

For those using CMake this probably seems silly, but for those of us using make because we haven't gotten around to it, this is useful.

Find the path to the opencv.pc file and call pkg-config, which will then output everything you need into your call to g++/clang++. As mentioned above, you can also just call the pkg-config binary and pass it the opencv.pc file, then you have the library order, but of course it would be better to directly use the opencv.pc file.

For instance, in my makefile:

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

Hope this helps someone, and thanks to ChronoTrigger for getting me here.

Joel Teply
  • 3,260
  • 1
  • 31
  • 21
  • Joel, could you please help me with cmake? I'm not that familiar with cmake and I'm linking (target_link_libraries) each library individually but cant do it in the right order. Is there a better way in cmake as you said "silly"? thanks – Paolo Vigori Dec 02 '16 at 18:03
0

Since it seems you installed OpenCV not in /usr, which is the default location, I think the reason for undefined reference is not the lib link order but more likely the libs not being linked, because your_lib_dir is not in LD_LIBRARY_PATH, as it was my case too. Add your OpenCV lib dir to the LD_LIBRARY_PATH like here. For a build with cmake, you can do this:
SET(OpenCV_DIR "${DIR_WHERE_YOU_INSTALLED_OPENCV}")
find_package(OpenCV 2.4.5 REQUIRED CONFIG EXACT) DIR_WHERE_YOU_INSTALLED_OPENCV is the path that contains both /lib and /include

re-fused
  • 11
  • 3