When I try to set up the build by CMake, it actually recognized that the openjpeg lib has been installed in WSL2 ( ubuntu 22.04 ),:
-- Media I/O:
– ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
– JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
– WEBP: build (ver encoder: 0x020f)
– PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
– TIFF: build (ver 42 - 4.2.0)
– JPEG 2000: OpenJPEG (ver 2.4.0)
but when I built it, this error occurred:
In file included from /home/samwu/opencv_build/opencv/modules/imgcodecs/src/grfmts.hpp:55,
from /home/samwu/opencv_build/opencv/modules/imgcodecs/src/loadsave.cpp:47:
/home/samwu/opencv_build/opencv/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.hpp:13:10: fatal error:
openjpeg.h: No such file or directory
13 | #include <openjpeg.h>
| ^~~~~~~~~~~~
compilation terminated.
make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/build.make:76: modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/loadsave.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2402: modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
make: *** [Makefile:166: all] Error 2
I tried to paste all the correspondent header file to /usr/include , and it did find them, but still:
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/loadsave.cpp.o: in function `std::_Sp_counted_ptr_inplace<cv::Jpeg2KJP2OpjDecoder, std::allocator<cv::Jpeg2KJP2OpjDecoder>, (__gnu_cxx::_Lock_policy)2>::_M_dispose()':
loadsave.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJP2OpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJP2OpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x24): undefined reference to `opj_image_destroy'
/usr/bin/ld: loadsave.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJP2OpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJP2OpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x35): undefined reference to `opj_destroy_codec'
/usr/bin/ld: loadsave.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJP2OpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJP2OpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x46): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/loadsave.cpp.o: in function `std::_Sp_counted_ptr_inplace<cv::Jpeg2KJ2KOpjDecoder, std::allocator<cv::Jpeg2KJ2KOpjDecoder>, (__gnu_cxx::_Lock_policy)2>::_M_dispose()':
loadsave.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJ2KOpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJ2KOpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x24): undefined reference to `opj_image_destroy'
/usr/bin/ld: loadsave.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJ2KOpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJ2KOpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x35): undefined reference to `opj_destroy_codec'
/usr/bin/ld: loadsave.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJ2KOpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceIN2cv19Jpeg2KJ2KOpjDecoderESaIS1_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x46): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::detail::Jpeg2KOpjDecoderBase::~Jpeg2KOpjDecoderBase()':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBaseD2Ev[_ZN2cv6detail20Jpeg2KOpjDecoderBaseD5Ev]+0x1f): undefined reference to `opj_image_destroy'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBaseD2Ev[_ZN2cv6detail20Jpeg2KOpjDecoderBaseD5Ev]+0x30): undefined reference to `opj_destroy_codec'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBaseD2Ev[_ZN2cv6detail20Jpeg2KOpjDecoderBaseD5Ev]+0x41): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::Jpeg2KJ2KOpjDecoder::~Jpeg2KJ2KOpjDecoder()':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJ2KOpjDecoderD2Ev[_ZN2cv19Jpeg2KJ2KOpjDecoderD5Ev]+0x1f): undefined reference to `opj_image_destroy'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJ2KOpjDecoderD2Ev[_ZN2cv19Jpeg2KJ2KOpjDecoderD5Ev]+0x30): undefined reference to `opj_destroy_codec'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJ2KOpjDecoderD2Ev[_ZN2cv19Jpeg2KJ2KOpjDecoderD5Ev]+0x41): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::Jpeg2KJP2OpjDecoder::~Jpeg2KJP2OpjDecoder()':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJP2OpjDecoderD2Ev[_ZN2cv19Jpeg2KJP2OpjDecoderD5Ev]+0x1f): undefined reference to `opj_image_destroy'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJP2OpjDecoderD2Ev[_ZN2cv19Jpeg2KJP2OpjDecoderD5Ev]+0x30): undefined reference to `opj_destroy_codec'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJP2OpjDecoderD2Ev[_ZN2cv19Jpeg2KJP2OpjDecoderD5Ev]+0x41): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::detail::Jpeg2KOpjDecoderBase::~Jpeg2KOpjDecoderBase()':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBaseD0Ev[_ZN2cv6detail20Jpeg2KOpjDecoderBaseD5Ev]+0x1f): undefined reference to `opj_image_destroy'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBaseD0Ev[_ZN2cv6detail20Jpeg2KOpjDecoderBaseD5Ev]+0x30): undefined reference to `opj_destroy_codec'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBaseD0Ev[_ZN2cv6detail20Jpeg2KOpjDecoderBaseD5Ev]+0x41): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::Jpeg2KJP2OpjDecoder::~Jpeg2KJP2OpjDecoder()':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJP2OpjDecoderD0Ev[_ZN2cv19Jpeg2KJP2OpjDecoderD5Ev]+0x1f): undefined reference to `opj_image_destroy'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJP2OpjDecoderD0Ev[_ZN2cv19Jpeg2KJP2OpjDecoderD5Ev]+0x30): undefined reference to `opj_destroy_codec'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJP2OpjDecoderD0Ev[_ZN2cv19Jpeg2KJP2OpjDecoderD5Ev]+0x41): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::Jpeg2KJ2KOpjDecoder::~Jpeg2KJ2KOpjDecoder()':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJ2KOpjDecoderD0Ev[_ZN2cv19Jpeg2KJ2KOpjDecoderD5Ev]+0x1f): undefined reference to `opj_image_destroy'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJ2KOpjDecoderD0Ev[_ZN2cv19Jpeg2KJ2KOpjDecoderD5Ev]+0x30): undefined reference to `opj_destroy_codec'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv19Jpeg2KJ2KOpjDecoderD0Ev[_ZN2cv19Jpeg2KJ2KOpjDecoderD5Ev]+0x41): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::(anonymous namespace)::setupLogCallbacks(void**)':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv12_GLOBAL__N_117setupLogCallbacksEPPv+0x78): undefined reference to `opj_set_error_handler'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv12_GLOBAL__N_117setupLogCallbacksEPPv+0x3e2): undefined reference to `opj_set_warning_handler'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::detail::Jpeg2KOpjDecoderBase::readHeader() [clone .cold]':
grfmt_jpeg2000_openjpeg.cpp:(.text.unlikely._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x4): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::detail::Jpeg2KOpjDecoderBase::readHeader()':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x92): undefined reference to `opj_stream_default_create'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0xa7): undefined reference to `opj_stream_set_user_data'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0xb6): undefined reference to `opj_stream_set_user_data_length'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0xc5): undefined reference to `opj_stream_set_read_function'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0xd4): undefined reference to `opj_stream_set_skip_function'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0xe3): undefined reference to `opj_stream_set_seek_function'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0xfb): undefined reference to `opj_stream_destroy'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x116): undefined reference to `opj_create_decompress'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x134): undefined reference to `opj_destroy_codec'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x156): undefined reference to `opj_set_default_decoder_parameters'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x165): undefined reference to `opj_setup_decoder'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x188): undefined reference to `opj_read_header'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x1ad): undefined reference to `opj_image_destroy'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x2a2): undefined reference to `opj_stream_create_default_file_stream'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase10readHeaderEv+0x2c1): undefined reference to `opj_stream_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::detail::Jpeg2KOpjDecoderBase::readData(cv::Mat&)':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv6detail20Jpeg2KOpjDecoderBase8readDataERNS_3MatE+0x8b): undefined reference to `opj_decode'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::Jpeg2KOpjEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&) [clone .cold]':
grfmt_jpeg2000_openjpeg.cpp:(.text.unlikely._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x51): undefined reference to `opj_stream_destroy'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text.unlikely._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x59): undefined reference to `opj_destroy_codec'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text.unlikely._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x73): undefined reference to `opj_image_destroy'
/usr/bin/ld: CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000_openjpeg.cpp.o: in function `cv::Jpeg2KOpjEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)':
grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x114): undefined reference to `opj_set_default_encoder_parameters'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x66e): undefined reference to `opj_image_create'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x8a2): undefined reference to `opj_create_compress'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x8c9): undefined reference to `opj_setup_encoder'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x8e4): undefined reference to `opj_stream_create_default_file_stream'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x8fe): undefined reference to `opj_start_compress'/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x911): undefined reference to `opj_encode'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x924): undefined reference to `opj_end_compress'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x934): undefined reference to `opj_stream_destroy'/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x93c): undefined reference to `opj_destroy_codec'
/usr/bin/ld: grfmt_jpeg2000_openjpeg.cpp:(.text._ZN2cv16Jpeg2KOpjEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x956): undefined reference to `opj_image_destroy'
/usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.7.0: unable to sort relocs - they are of an unknown size
collect2: error: ld returned 1 exit status
make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/build.make:445: lib/libopencv_imgcodecs.so.4.7.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:2402: modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
make: *** [Makefile:166: all] Error 2
(ps: the openjpeg lib has been installed, and all the files the build needs are stored in /usr/include/openjpeg-2.4)
So, how can I fix this?