nvjpeg with opencv compile problem

First, we want to use the element ‘nvjpegenc’ in Gstreamer. But when I compile I get an error that says: ‘JPEG parameter struct mismatch: library thinks size is 432, caller expects 488’ .I found the solution in the URL ’ https://devtalk.nvidia.com/default/topic/846312/don-t-work-nvjpeg-in-gstreamer/ ’. So I replaced this ‘libjpeg.so’ library the library /usr/lib/arm-linux-gnueabihf/tegra/libjpeg.so and ‘nvjpegenc’ can work.
But I get another error (see below), when this code compiled with the OpenCV modules.

gcc –wall –c jpeg_save.c pkg-config --cflags –libs gsteamer-1.0 –lnvgstjpeg
g++ -LA jpeg_cxx.o jpeg_save.o ‘pkg-config –cflags –libs gstreamer-1.0’ –lnvgstjpeg ‘pkg-config –cflags –libs opencv’ –L/usr/local/cuda/lib –std=c++11
/usr/lib/libopencv_highgui.so: undefined reference to ‘jpeg_alloc_huff_table@LIBJPEG_8.0’
/usr/lib/libopencv_highgui.so: undefined reference to ‘jpeg_finish_decompress@LIBJPEG_8.0’
/usr/lib/libopencv_highgui.so: undefined reference to ‘jpeg_start_compress@LIBJPEG_8.0’
//usr/ilb/arm-linux-gnueabihf/libtiff.so.5: undefined reference to ‘jpeg_destroy@LIBJPEG_8.0’
/usr/lib/libopencv_highgui.so: undefined reference to ‘jpeg_finish_compress@LIBJPEG_8.0’
/usr/lib/libopencv_highgui.so: undefined reference to ‘jpeg_resync_to_restart@LIBJPEG_8.0’
/usr/lib/libopencv_highgui.so: undefined reference to ‘jpeg_set_default@LIBJPEG_8.0’
//usr/ilb/arm-linux-gnueabihf/libtiff.so.5: undefined reference to ‘jpeg_write_tables@LIBJPEG_8.0’
//usr/ilb/arm-linux-gnueabihf/libtiff.so.5: undefined reference to ‘jpeg_read_raw_data@LIBJPEG_8.0’
/usr/lib/libopencv_highgui.so: undefined reference to ‘jpeg_read_scanlines@LIBJPEG_8.0’
/usr/lib/libopencv_highgui.so: undefined reference to ‘jpeg_destroy_compress@LIBJPEG_8.0’
/usr/lib/libopencv_highgui.so: undefined reference to ‘jpeg_start_decompress@LIBJPEG_8.0’
//usr/ilb/arm-linux-gnueabihf/libtiff.so.5: undefined reference to ‘jpeg_write_raw_data@LIBJPEG_8.0’

I guess the reason for this error is that the OpenCV wants the normal version of libjpeg.so when Gstreamer hopes that this address will be based on a special version of the library -- /usr/lib/arm-linux-gnueabihf/tegra/ libjpeg.so. 
So How to resolve this problem? Is there a version of libjpeg.so applies to both the OpenCV and the Gstreamer?
  1. Is it necessary to link the library nvgstjpeg to the project?
  2. Try to see at depending opencv libraries and nvgstjpeg library. If you are lucky, they will refer to different files (for example, one on libjpeg.so.8, the other on libjpeg.so.8.0). In this case it will be possible to substitute a different libraries in these references

Thank you for replying.
1.We want to konw how fast nvgstjpeg can run.
2.They really are different files,when opencv libraries on /usr/lib/arm-linux-gnueabihf/libjpeg.so.8 and nvgstjpeg library on /usr/lib/arm-linux-gnueabihf/libjpeg.so.And libjpeg.so.8 -> libjpeg.so.8.0.2 .In these links, I get this error ‘JPEG parameter struct mismatch: library thinks size is 432, caller expects 488’.
How could I fix it?

  1. Library nvgstjpeg downloads gstreamer, and no no need to load it yourself
  2. In this case, /usr/lib/arm-linux-gnueabihf/libjpeg.so.8 must point to native libraries libjpeg, /usr/lib/arm-linux-gnueabihf/libjpeg.so must point to libjpeg in the folder tegra/
    But hardly have something good that will be loaded these 2 libraries at the same time (because the names in them intersect). In this case, I do not know that you can tell. But as I understand it, you have a problem occurs at the stage of linking

Yes, we want to use the nvgstjpeg in our project.And I agree that is a problem occurs at the stage of linking.Normally,the /usr/lib/arm-linux-gnueabihf/libjpeg.so doesn’t point to libjpeg in the folder tegra/,and the nvgstjpeg can’t work.So I adopt your solution in the URL ’ https://devtalk.nvidia.com/default/topic/846312/don-t-work-nvjpeg-in-gstreamer/ ’, replace this ‘libjpeg.so’ library the library /usr/lib/arm-linux-gnueabihf/tegra/libjpeg.And then‘nvjpegenc’ can work, but the OpenCV modules can’t work.
Now I’m trying to use the OpenCV library in the folder /usr/lib/arm-linux-gnueabihf.(Actually,I don’t know much about it.Do you know it? What’s the difference between gcc and arm-linux-gneabihf-gcc?)
Wish it works.

Replace libjpeg.so was a very “tough” decision. A better solution is the substitution of references and libjpeg.so, libjpeg.so.8, as I wrote above. But this is unlikely to help launch the application, as is most likely, both loaded library will overwrite function names each other. In such a case, it is likely to make an application in 2 parts, one will work with gstreamer, and the other with opencv, and exchange between the parts on some protocol. Or look for another solution (I do not know what else to offer)
About why not a link, I do not know the reason, but you may want to add the library libjpeg in depending

Label as “arm-linux-gnueabihf-gcc” means the gcc is specifically designed for code output to GNU E-ABI hard float convention…the “linux” in the name implies linux calling convention (versus bare metal). Typically you see the expanded naming when there is a desire to specifically mark what architecture the tool is designed for, which often means a cross compiler. E.G., if you were to put a cross compiler on x86_64 designed to put out code for Jetson TK1, then the name you have above would be used to differentiate those cross compiler tools from the native x86_64 gcc. There will often be places such tools are marked for a specific architecture even if not used as a cross compiler. Backwards compatibility may be another reason to see multiple architectures on a single machine.