Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compile OpenJPEG decoder plugin #1134

Open
donaldi opened this issue Feb 28, 2024 · 8 comments · May be fixed by #1135
Open

Cannot compile OpenJPEG decoder plugin #1134

donaldi opened this issue Feb 28, 2024 · 8 comments · May be fixed by #1135

Comments

@donaldi
Copy link

donaldi commented Feb 28, 2024

I'm trying to compile the libheif library from source on my fedora 39 machine. On both the latest tagged release and the master branch I run into this error:

I'm not sure what I'm doing wrong or how to fix it?

[ 87%] Building CXX object libheif/plugins/CMakeFiles/heif-j2kdec.dir/decoder_openjpeg.cc.o
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc: In function ‘const char* openjpeg_plugin_name()’:
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:46:3: error: ‘snprintf’ was not declared in this scope
   46 |   snprintf(plugin_name, MAX_PLUGIN_NAME_LENGTH, "OpenJPEG %s", opj_version());
      |   ^~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:30:1: note: ‘snprintf’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’?
   29 | #include <cassert>
  +++ |+#include <cstdio>
   30 | 
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc: At global scope:
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:117:8: error: ‘OPJ_SIZE_T’ does not name a type
  117 | static OPJ_SIZE_T opj_memory_stream_read(void* p_buffer, OPJ_SIZE_T p_nb_bytes, void* p_user_data)
      |        ^~~~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:149:8: error: ‘OPJ_SIZE_T’ does not name a type
  149 | static OPJ_SIZE_T opj_memory_stream_write(void* p_buffer, OPJ_SIZE_T p_nb_bytes, void* p_user_data)
      |        ^~~~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:158:8: error: ‘OPJ_OFF_T’ does not name a type
  158 | static OPJ_OFF_T opj_memory_stream_skip(OPJ_OFF_T p_nb_bytes, void* p_user_data)
      |        ^~~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:191:8: error: ‘OPJ_BOOL’ does not name a type
  191 | static OPJ_BOOL opj_memory_stream_seek(OPJ_OFF_T p_nb_bytes, void* p_user_data)
      |        ^~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:220:1: error: ‘opj_stream_t’ does not name a type
  220 | opj_stream_t* opj_stream_create_default_memory_stream(openjpeg_decoder* p_decoder, OPJ_BOOL p_is_read_stream)
      | ^~~~~~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc: In function ‘heif_error openjpeg_decode_image(void*, heif_image**)’:
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:256:3: error: ‘OPJ_BOOL’ was not declared in this scope
  256 |   OPJ_BOOL success;
      |   ^~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:258:3: error: ‘opj_codec_t’ was not declared in this scope; did you mean ‘opj_poc_t’?
  258 |   opj_codec_t* l_codec;
      |   ^~~~~~~~~~~
      |   opj_poc_t
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:258:16: error: ‘l_codec’ was not declared in this scope
  258 |   opj_codec_t* l_codec;
      |                ^~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:262:35: error: ‘OPJ_CODEC_J2K’ was not declared in this scope; did you mean ‘CODEC_J2K’?
  262 |   l_codec = opj_create_decompress(OPJ_CODEC_J2K);
      |                                   ^~~~~~~~~~~~~
      |                                   CODEC_J2K
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:263:3: error: ‘success’ was not declared in this scope
  263 |   success = opj_setup_decoder(l_codec, &decompression_parameters);
      |   ^~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:272:11: error: expected ‘;’ before ‘is_read_stream’
  272 |   OPJ_BOOL is_read_stream = true;
      |           ^~~~~~~~~~~~~~~
      |           ;
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:273:3: error: ‘opj_stream_t’ was not declared in this scope
  273 |   opj_stream_t* stream = opj_stream_create_default_memory_stream(decoder, is_read_stream);
      |   ^~~~~~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:273:17: error: ‘stream’ was not declared in this scope; did you mean ‘strcat’?
  273 |   opj_stream_t* stream = opj_stream_create_default_memory_stream(decoder, is_read_stream);
      |                 ^~~~~~
      |                 strcat
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:273:75: error: ‘is_read_stream’ was not declared in this scope
  273 |   opj_stream_t* stream = opj_stream_create_default_memory_stream(decoder, is_read_stream);
      |                                                                           ^~~~~~~~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:273:26: error: ‘opj_stream_create_default_memory_stream’ was not declared in this scope
  273 |   opj_stream_t* stream = opj_stream_create_default_memory_stream(decoder, is_read_stream);
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:278:13: error: ‘opj_read_header’ was not declared in this scope
  278 |   success = opj_read_header(stream, l_codec, &image);
      |             ^~~~~~~~~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:288:35: error: ‘OPJ_CLRSPC_UNSPECIFIED’ was not declared in this scope; did you mean ‘CLRSPC_UNSPECIFIED’?
  288 |   else if ((image->color_space != OPJ_CLRSPC_UNSPECIFIED) && (image->color_space != OPJ_CLRSPC_SRGB)) {
      |                                   ^~~~~~~~~~~~~~~~~~~~~~
      |                                   CLRSPC_UNSPECIFIED
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:288:85: error: ‘OPJ_CLRSPC_SRGB’ was not declared in this scope; did you mean ‘CLRSPC_SRGB’?
  288 |   else if ((image->color_space != OPJ_CLRSPC_UNSPECIFIED) && (image->color_space != OPJ_CLRSPC_SRGB)) {
      |                                                                                     ^~~~~~~~~~~~~~~
      |                                                                                     CLRSPC_SRGB
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:306:13: error: ‘opj_end_decompress’ was not declared in this scope; did you mean ‘opj_create_decompress’?
  306 |   success = opj_end_decompress(l_codec, stream);
      |             ^~~~~~~~~~~~~~~~~~
      |             opj_create_decompress
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:314:3: error: ‘opj_stream_destroy’ was not declared in this scope; did you mean ‘opj_image_destroy’?
  314 |   opj_stream_destroy(stream);
      |   ^~~~~~~~~~~~~~~~~~
      |   opj_image_destroy
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:359:24: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
  359 |   for (size_t c = 0; c < image->numcomps; c++) {
      |                      ~~^~~~~~~~~~~~~~~~~
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc: At global scope:
/home/username/tmp/libheif-1.17.6/libheif/plugins/decoder_openjpeg.cc:212:13: error: ‘void opj_memory_stream_do_nothing(void*)’ defined but not used [-Werror=unused-function]
  212 | static void opj_memory_stream_do_nothing(void* p_user_data)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [libheif/plugins/CMakeFiles/heif-j2kdec.dir/build.make:76: libheif/plugins/CMakeFiles/heif-j2kdec.dir/decoder_openjpeg.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:563: libheif/plugins/CMakeFiles/heif-j2kdec.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
@bradh
Copy link
Contributor

bradh commented Feb 28, 2024

Can you say which compiler you are using? Also, which OpenJPEG version do you have?

@donaldi
Copy link
Author

donaldi commented Feb 28, 2024

Of course, sorry:

-- The C compiler identification is GNU 13.2.1
-- The CXX compiler identification is GNU 13.2.1

(from the cmake output; cmake is 3.27.7 and make is GNU Make 4.4.1).

Is this the relevant OpenJPEG info?

$ dnf list installed |grep -i openjpeg
openjpeg.x86_64                                      1.5.1-35.fc39                       @fedora                   
openjpeg-devel.x86_64                                1.5.1-35.fc39                       @fedora                   
openjpeg-libs.x86_64                                 1.5.1-35.fc39                       @fedora                   
openjpeg2.x86_64                                     2.5.0-5.fc39                        @fedora                   
openjpeg2-devel.x86_64                               2.5.0-5.fc39                        @fedora                   
openjpeg2-tools.x86_64                               2.5.0-5.fc39                        @fedora 

@bradh
Copy link
Contributor

bradh commented Feb 28, 2024

That is a pretty new compiler, and could be part of the issue. Probably not the only problem though, from that list of warnings.

For OpenJPEG, I was looking for what it is linking to. Possibly the entry in the CMakeCache.txt is the easiest way to see. Mine looks like:

OpenJPEG_DIR:PATH=/usr/lib/x86_64-linux-gnu/openjpeg-2.1

Do you have something similar?

@donaldi
Copy link
Author

donaldi commented Feb 28, 2024

Thanks, appreciate these quick responses! I have this in my CMakeCache.txt:

OpenJPEG_DIR:PATH=/usr/lib64/openjpeg-1.5

Which looks older than yours? Is this connected to the openjpeg libs installed? I notice the openjpeg lib is v1.5 (while the openjpeg2 lib is 2.5). Would it help to try compiling openjpeg from source first?

@kmilos
Copy link
Contributor

kmilos commented Feb 28, 2024

That is a pretty new compiler, and could be part of the issue.

libheif builds fine w/ this compiler in e.g. MSYS2 UCRT64 environment...

Would it help to try compiling openjpeg from source first?

No need, but you somehow need to make sure the 2.5 version is used, not the 1.5 one... Can you uninstall all 1.5 packages, are they required by something?

@bradh Maybe the CMake find procedure should explicitly check for the suitable version?

@bradh
Copy link
Contributor

bradh commented Feb 28, 2024

It looks like you have two versions, and that cmake is picking up the older one. So I think its more that we need to make sure we pick up the right one.

@kmilos
Copy link
Contributor

kmilos commented Feb 28, 2024

I think find_package(OpenJPEG 2) should do it.

@donaldi Please test this before removing 1.5, would be interesting to know if that handles two installed versions.

@kmilos kmilos linked a pull request Feb 28, 2024 that will close this issue
@donaldi
Copy link
Author

donaldi commented Feb 28, 2024

Thanks for your help, yes @kmilos I can confirm that just changing that line in CMakeLists.txt let the compilation go through to completion successfully, without removing the older package. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants