6

Ater compiling libjpeg and then using it, I stumbled upon the problem:

JPEG parameter struct mismatch: library thinks size is 512, caller expects 492

after which the program halts. This happens specifically with the structs struct jpeg_decompress_struct and struct jpeg_compress_struct. If the checks are removed on these structs, the program crashes with a null pointer exception, and the struct members contain garbage.

The error occurs with either precompiled binaries from version 6b, or with precompiled version 9a, and with the compiled version 9a; compiled with MinGW, MSYS 1.0, on windows (32 bit). Messing around in the config files does not help; the number 492 can change, but never equals 512 in order for the program to function.

The libjpeg compilation did create a valid cjpeg.exe and djpeg.exe.

Any ideas?

user3F31A28
  • 104
  • 2
  • 13
  • 1
    This sounds like you've got two (or more) versions of libjpeg installed. The headers must match the library; check to make sure your include paths and library paths sync up. – nneonneo Apr 07 '14 at 23:59
  • http://stackoverflow.com/questions/4306186/structure-padding-and-structure-packing look at the source, find the struct, and see if there is a way to make it right using these build tools – Gábor Buella Apr 08 '14 at 00:00
  • the version can be OK, there is a check for `JPEG_LIB_VERSION` before the check for the size of the struct – Gábor Buella Apr 08 '14 at 00:14
  • Maybe just try to add `__attribute__ ((__packed__))` attribute to the structs, so they might get packed to 492 bytes, as the caller expects. – Gábor Buella Apr 08 '14 at 00:26
  • The packed attribute did not compact them to 492 but to 508 – user3F31A28 Apr 08 '14 at 00:48
  • Please check if you have multiple copies of libjpeg installed. point the one which is throwing the error to the correct copy of libjpeg using linking i.e ln -s command. – bgth Apr 05 '16 at 17:43

2 Answers2

1

In my case, the problem was that the library and my program were compiled with different values of HAVE_BOOLEAN, so boolean type had different size.

Library was compiled with HAVE_BOOLEAN not defined, so it was using int as defined in libjpeg. Program was compiled with HAVE_BOOLEAN defined, and because some other headers were included before libjpeg, it was using unsigned char as defined in Windows RTL.

Reason I used HAVE_BOOLEAN was to fix compile error about this, but it then caused a linker error. Instead, the proper solution was to not include Windows RTL (or any file that includes it) in the file that uses libjpeg.

VLL
  • 9,634
  • 1
  • 29
  • 54
0

It seems that the static package architecture does not conform to the current package architecture when the linker is connected. It is recommended to download the source code and compile it into a static library with the same parameters. Try again, remember to quote the correct version.