Minhui Wu
Minhui Wu

Reputation: 15

package opencv libraries with my own library

I am trying to package the opencv libraries with my own library. I do it like this:

   ar x libopencv_highgui.a
   ar x libopencv_core.a
   ar x libopencv_imgproc.a
   ar x libmyown.a
   ar cru libnew.a *.o

when I use this new library libnew.a, it comes out a lot of errors like this:

grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x282): undefined reference to CvtPaletteToGray(PaletteEntry const*, unsigned char*, int)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x321): undefined reference toFillColorRow1(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x376): undefined reference to FillColorRow1(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x3b5): undefined reference toicvCvt_BGR2Gray_8u_C3C1R(unsigned char const*, int, unsigned char*, int, CvSize, int)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x449): undefined reference to FillGrayRow4(unsigned char*, unsigned char*, int, unsigned char*)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x492): undefined reference toFillColorRow4(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x524): undefined reference to FillGrayRow8(unsigned char*, unsigned char*, int, unsigned char*)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x567): undefined reference toFillColorRow8(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x5f9): undefined reference to icvCvt_BGR5552BGR_8u_C2C3R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x669): undefined reference toicvCvt_BGR5552Gray_8u_C2C1R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x6fa): undefined reference to icvCvt_BGR5652BGR_8u_C2C3R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x769): undefined reference toicvCvt_BGR5652Gray_8u_C2C1R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x843): undefined reference to icvCvt_BGR2Gray_8u_C3C1R(unsigned char const*, int, unsigned char*, int, CvSize, int)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x8dc): undefined reference toicvCvt_BGRA2BGR_8u_C4C3R(unsigned char const*, int, unsigned char*, int, CvSize, int)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0x94c): undefined reference to icvCvt_BGRA2Gray_8u_C4C1R(unsigned char const*, int, unsigned char*, int, CvSize, int)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xa2c): undefined reference toFillUniColor(unsigned char*, unsigned char*&, int, int, int&, int, int, PaletteEntry)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xaba): undefined reference to FillColorRow8(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xb4a): undefined reference toFillUniGray(unsigned char*, unsigned char*&, int, int, int&, int, int, unsigned char)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xbad): undefined reference to FillUniColor(unsigned char*, unsigned char*&, int, int, int&, int, int, PaletteEntry)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xc15): undefined reference toFillGrayRow8(unsigned char*, unsigned char*, int, unsigned char*)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xc46): undefined reference to FillUniGray(unsigned char*, unsigned char*&, int, int, int&, int, int, unsigned char)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xe18): undefined reference toFillColorRow4(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xe6a): undefined reference to FillUniColor(unsigned char*, unsigned char*&, int, int, int&, int, int, PaletteEntry)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xeb3): undefined reference toFillUniGray(unsigned char*, unsigned char*&, int, int, int&, int, int, unsigned char)' grfmt_bmp.cpp:(.text._ZN2cv10BmpDecoder8readDataERNS_3MatE+0xecb): undefined reference to FillGrayRow4(unsigned char*, unsigned char*, int, unsigned char*)' ./lib/libbasmk.a(grfmt_jpeg.cpp.o): In functioncv::JpegDecoder::readData(cv::Mat&)': grfmt_jpeg.cpp:(.text._ZN2cv11JpegDecoder8readDataERNS_3MatE+0x1b4): undefined reference to icvCvt_CMYK2BGR_8u_C4C3R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_jpeg.cpp:(.text._ZN2cv11JpegDecoder8readDataERNS_3MatE+0x221): undefined reference toicvCvt_CMYK2Gray_8u_C4C1R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_jpeg.cpp:(.text._ZN2cv11JpegDecoder8readDataERNS_3MatE+0x254): undefined reference to icvCvt_BGR2RGB_8u_C3R(unsigned char const*, int, unsigned char*, int, CvSize)' ./lib/libbasmk.a(grfmt_jpeg.cpp.o): In functioncv::JpegEncoder::write(cv::Mat const&, std::vector > const&)': grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x49a): undefined reference to icvCvt_BGR2RGB_8u_C3R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_jpeg.cpp:(.text._ZN2cv11JpegEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x510): undefined reference toicvCvt_BGRA2BGR_8u_C4C3R(unsigned char const*, int, unsigned char*, int, CvSize, int)' ./lib/libbasmk.a(grfmt_pxm.cpp.o): In function cv::PxMEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)': grfmt_pxm.cpp:(.text._ZN2cv10PxMEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x437): undefined reference toicvCvt_BGR2RGB_16u_C3R(unsigned short const*, int, unsigned short*, int, CvSize)' grfmt_pxm.cpp:(.text._ZN2cv10PxMEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x539): undefined reference to icvCvt_BGR2RGB_8u_C3R(unsigned char const*, int, unsigned char*, int, CvSize)' ./lib/libbasmk.a(grfmt_pxm.cpp.o): In functioncv::PxMDecoder::readData(cv::Mat&)': grfmt_pxm.cpp:(.text._ZN2cv10PxMDecoder8readDataERNS_3MatE+0x30d): undefined reference to FillGrayPalette(PaletteEntry*, int, bool)' grfmt_pxm.cpp:(.text._ZN2cv10PxMDecoder8readDataERNS_3MatE+0x410): undefined reference toicvCvt_BGR2RGB_8u_C3R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_pxm.cpp:(.text._ZN2cv10PxMDecoder8readDataERNS_3MatE+0x4ee): undefined reference to icvCvt_BGR2Gray_8u_C3C1R(unsigned char const*, int, unsigned char*, int, CvSize, int)' grfmt_pxm.cpp:(.text._ZN2cv10PxMDecoder8readDataERNS_3MatE+0x5af): undefined reference toicvCvt_BGR2RGB_16u_C3R(unsigned short const*, int, unsigned short*, int, CvSize)' grfmt_pxm.cpp:(.text._ZN2cv10PxMDecoder8readDataERNS_3MatE+0x60c): undefined reference to icvCvt_BGRA2Gray_16u_CnC1R(unsigned short const*, int, unsigned short*, int, CvSize, int, int)' grfmt_pxm.cpp:(.text._ZN2cv10PxMDecoder8readDataERNS_3MatE+0x6fa): undefined reference toFillGrayRow1(unsigned char*, unsigned char*, int, unsigned char*)' grfmt_pxm.cpp:(.text._ZN2cv10PxMDecoder8readDataERNS_3MatE+0x766): undefined reference to FillColorRow8(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_pxm.cpp:(.text._ZN2cv10PxMDecoder8readDataERNS_3MatE+0x7a9): undefined reference toFillColorRow1(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_pxm.cpp:(.text._ZN2cv10PxMDecoder8readDataERNS_3MatE+0x7d1): undefined reference to FillGrayRow8(unsigned char*, unsigned char*, int, unsigned char*)' ./lib/libbasmk.a(grfmt_sunras.cpp.o): In functioncv::SunRasterDecoder::readHeader()': grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder10readHeaderEv+0x248): undefined reference to IsColorPalette(PaletteEntry*, int)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder10readHeaderEv+0x278): undefined reference toFillGrayPalette(PaletteEntry*, int, bool)' ./lib/libbasmk.a(grfmt_sunras.cpp.o): In function cv::SunRasterDecoder::readData(cv::Mat&)': grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x2ea): undefined reference toFillGrayRow1(unsigned char*, unsigned char*, int, unsigned char*)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x37c): undefined reference to FillGrayRow8(unsigned char*, unsigned char*, int, unsigned char*)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x3ca): undefined reference toFillColorRow8(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x41a): undefined reference to FillColorRow1(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x45e): undefined reference toCvtPaletteToGray(PaletteEntry const*, unsigned char*, int)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x4e2): undefined reference to icvCvt_BGRA2BGR_8u_C4C3R(unsigned char const*, int, unsigned char*, int, CvSize, int)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x573): undefined reference toicvCvt_BGRA2Gray_8u_C4C1R(unsigned char const*, int, unsigned char*, int, CvSize, int)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x641): undefined reference to icvCvt_BGR2Gray_8u_C3C1R(unsigned char const*, int, unsigned char*, int, CvSize, int)' fmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x677): undefined reference toicvCvt_BGR2RGB_8u_C3R(unsigned char const*, int, unsigned char*, int, CvSize)%n grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x757): undefined reference to FillColorRow8(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x7bc): undefined reference toFillUniColor(unsigned char*, unsigned char*&, int, int, int&, int, int, PaletteEntry)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x85d): undefined reference to FillGrayRow8(unsigned char*, unsigned char*, int, unsigned char*)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x898): undefined reference toFillUniGray(unsigned char*, unsigned char*&, int, int, int&, int, int, unsigned char)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x985): undefined reference to FillColorRow1(unsigned char*, unsigned char*, int, PaletteEntry*)' grfmt_sunras.cpp:(.text._ZN2cv16SunRasterDecoder8readDataERNS_3MatE+0x9df): undefined reference toFillGrayRow1(unsigned char*, unsigned char*, int, unsigned char*)' ./lib/libbasmk.a(grfmt_tiff.cpp.o): In function cv::TiffDecoder::readData(cv::Mat&)': grfmt_tiff.cpp:(.text._ZN2cv11TiffDecoder8readDataERNS_3MatE+0x600): undefined reference toicvCvt_BGRA2Gray_8u_C4C1R(unsigned char const*, int, unsigned char*, int, CvSize, int)' grfmt_tiff.cpp:(.text._ZN2cv11TiffDecoder8readDataERNS_3MatE+0x67e): undefined reference to icvCvt_BGRA2BGR_8u_C4C3R(unsigned char const*, int, unsigned char*, int, CvSize, int)' grfmt_tiff.cpp:(.text._ZN2cv11TiffDecoder8readDataERNS_3MatE+0x792): undefined reference toicvCvt_BGRA2BGR_16u_C4C3R(unsigned short const*, int, unsigned short*, int, CvSize, int)' grfmt_tiff.cpp:(.text._ZN2cv11TiffDecoder8readDataERNS_3MatE+0x823): undefined reference to icvCvt_BGRA2Gray_16u_CnC1R(unsigned short const*, int, unsigned short*, int, CvSize, int, int)' grfmt_tiff.cpp:(.text._ZN2cv11TiffDecoder8readDataERNS_3MatE+0x8b9): undefined reference toicvCvt_BGR2RGB_16u_C3R(unsigned short const*, int, unsigned short*, int, CvSize)' grfmt_tiff.cpp:(.text._ZN2cv11TiffDecoder8readDataERNS_3MatE+0x917): undefined reference to icvCvt_Gray2BGR_16u_C1C3R(unsigned short const*, int, unsigned short*, int, CvSize)' ./lib/libbasmk.a(grfmt_tiff.cpp.o): In functioncv::TiffEncoder::writeLibTiff(cv::Mat const&, std::vector > const&)': grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder12writeLibTiffERKNS_3MatERKSt6vectorIiSaIiEE+0x432): undefined reference to icvCvt_BGR2RGB_8u_C3R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder12writeLibTiffERKNS_3MatERKSt6vectorIiSaIiEE+0x488): undefined reference toicvCvt_BGRA2RGBA_8u_C4R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder12writeLibTiffERKNS_3MatERKSt6vectorIiSaIiEE+0x4d2): undefined reference to icvCvt_BGR2RGB_16u_C3R(unsigned short const*, int, unsigned short*, int, CvSize)' grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder12writeLibTiffERKNS_3MatERKSt6vectorIiSaIiEE+0x51c): undefined reference toicvCvt_BGRA2RGBA_16u_C4R(unsigned short const*, int, unsigned short*, int, CvSize)' ./lib/libbasmk.a(grfmt_tiff.cpp.o): In function cv::TiffEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)': grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x358): undefined reference toicvCvt_BGR2RGB_8u_C3R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x6e0): undefined reference to icvCvt_BGRA2RGBA_8u_C4R(unsigned char const*, int, unsigned char*, int, CvSize)' grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x733): undefined reference toicvCvt_BGR2RGB_16u_C3R(unsigned short const*, int, unsigned short*, int, CvSize)' grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x794): undefined reference to `icvCvt_BGRA2RGBA_16u_C4R(unsigned short const*, int, unsigned short*, int, CvSize)'

Upvotes: 0

Views: 305

Answers (1)

vinograd47
vinograd47

Reputation: 6420

opencv_imgproc and opencv_highgui module have source files with the same names (for example, util.cpp). The object file util.o from opencv_highgui is overwritten by object file with the same name from opencv_imgproc. That's why you got link errors.

Try to use MRI script mode of AR tool. Create a MRI script file (for example, script.mri) with the following content:

create libnew.a
addlib libopencv_core.a
addlib libopencv_imgproc.a
addlib libopencv_highgui.a
addlib libmyown.a
save
end

and use it with ar tool:

ar -M <script.mri

Upvotes: 1

Related Questions