Incorrect JPEG Version

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
vhmth
Posts: 13
Joined: 2014-02-06T15:49:55-07:00
Authentication code: 6789

Incorrect JPEG Version

Post by vhmth »

Hey guys!

So I've been trying to get things working on my end for quite a bit now, but am starting to be at a loss as to what's happening. This is my current situation:

* I need to build a number of delegates for MagickWand to use (libjpeg, libpng, libtiff, etc.), but am focusing on libjpeg for now (just a first step).
* I need to build MagickWand static libraries (libMagickCore-6.Q16.a and libMagickWand-6.Q16.a) and link them against the libjpeg delegate.
* I need to copy over those archives (as well as their header files) to another folder and use them to be linked against other objects (to use MagickWand).

Note that I am able to do all of this with no warnings (that I can see from the output), but, when I run a binary in the other folder (the repo I copy the MagickWand static files over to), it gives me the following error:

Code: Select all

Wrong JPEG library version: library is 90, caller expects 80
This seems strange since I built libjpeg myself. These are the versions that I am using:

* ImageMagick-6.8.7-8
* jpeg-8c

I have tried the approach of building libjpeg separately and then copying over the necessary files (libjpeg.a, libjpeg.la as well as all headers in include) and linked against that. I have also tried the approach outlined here by user "magick": viewtopic.php?t=13145 (that is - I used the "--enable-delegate-build" flag and copied the libjpeg folder into the ImageMagick source folder before configuring and building).

I am using CMake to outline the rules of building and making, and I'm using clang for the "CC" environment variable and the "CFLAGS" environment variable is set to "-O3 -g -DNDEBUG". This is what my configure command looks like (after building libjpeg and moving into the ImageMagick source directory named as "jpeg"):

Code: Select all

CONFIGURE_COMMAND env CC=clang CXX=clang++ CFLAGS=${CFLAGS} CXXFLAGS=${CXXFLAGS} ./configure --enable-static --disable-shared --enable-delegate-build --disable-installed --prefix=${BUILD_DIR}/ImageMagick
                             --without-bzlib --without-djvu --without-dps --without-fftw
                             --without-fpx --without-fontconfig --without-freetype
                             --without-jbig --without-jp2 --without-lcms --without-lcms2
                             --without-lqr --without-lzma --without-magick-plus-plus
                             --without-openexr --without-pango --without-tiff --without-webp
                             --without-xml --without-zlib
This is the useful output from "make":

Code: Select all

checking for JPEG... 
checking jconfig.h usability... yes
checking jconfig.h presence... yes
checking for jconfig.h... yes
checking jerror.h usability... yes
checking jerror.h presence... yes
checking for jerror.h... yes
checking jmorecfg.h usability... yes
checking jmorecfg.h presence... yes
checking for jmorecfg.h... yes
checking jpeglib.h usability... yes
checking jpeglib.h presence... yes
checking for jpeglib.h... yes
checking for jpeg_read_header in -ljpeg... yes
checking for JPEG library is version 6b or later... yes
checking if JPEG package is complete... yes
and

Code: Select all

ImageMagick is configured as follows. Please verify that this configuration
matches your expectations.

Host system type: x86_64-apple-darwin13.0.0
Build system type: x86_64-apple-darwin13.0.0

                  Option                        Value
-------------------------------------------------------------------------------
Shared libraries  --enable-shared=no		no
Static libraries  --enable-static=yes		yes
Module support    --with-modules=no		no
GNU ld            --with-gnu-ld=no		no
Quantum depth     --with-quantum-depth=16	16
High Dynamic Range Imagery
                  --enable-hdri=no		no

Delegate Configuration:
BZLIB             --with-bzlib=no		no
Autotrace         --with-autotrace=no		no
Dejavu fonts      --with-dejavu-font-dir=default	none
DJVU              --with-djvu=no		no
DPS               --with-dps=no		no
FFTW              --with-fftw=no		no
FlashPIX          --with-fpx=no		no
FontConfig        --with-fontconfig=no		no
FreeType          --with-freetype=no		no
GhostPCL          None				pcl6 (unknown)
GhostXPS          None				gxps (unknown)
Ghostscript       None				gs (unknown)
Ghostscript fonts --with-gs-font-dir=default	none
Ghostscript lib   --with-gslib=no		no
Graphviz          --with-gvc=no		
JBIG              --with-jbig=no		no
JPEG v1           --with-jpeg=yes		yes
JPEG-2000         --with-jp2=no		no
LCMS v1           --with-lcms=no		no
LCMS v2           --with-lcms2=no		no
LQR               --with-lqr=no		no
LTDL              --with-ltdl=yes		no
LZMA              --with-lzma=no		
Magick++          --with-magick-plus-plus=no	no
MUPDF             --with-mupdf=no		no
OpenEXR           --with-openexr=no		no
PANGO             --with-pango=no		no
PERL              --with-perl=no		no
PNG               --with-png=yes		no
RSVG              --with-rsvg=no		no
TIFF              --with-tiff=no		no
WEBP              --with-webp=no		no
Windows fonts     --with-windows-font-dir=	none
WMF               --with-wmf=no		no
X11               --with-x=			no
XML               --with-xml=no		no
ZLIB              --with-zlib=no		yes

X11 Configuration:
      X_CFLAGS        = 
      X_PRE_LIBS      = 
      X_LIBS          = 
      X_EXTRA_LIBS    = 

Options used to compile and link:
  PREFIX          = /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick
  EXEC-PREFIX     = /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick
  VERSION         = 6.8.7
  CC              = clang
  CFLAGS          = -Wall -fexceptions -D_FORTIFY_SOURCE=0 -D_THREAD_SAFE -pthread -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
  CPPFLAGS        = -I/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/include/ImageMagick-6
  PCFLAGS         = -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
  DEFS            = -DHAVE_CONFIG_H
  LDFLAGS         = -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg/.libs -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/magick -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/wand
  MAGICK_LDFLAGS  = -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/lib -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg/.libs -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/magick -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/wand
  LIBS            = -ljpeg -lz -lm
  CXX             = clang++
  CXXFLAGS        = -D_THREAD_SAFE -pthread
  FEATURES        = DPC
  DELEGATES       = mpeg jpeg zlib
I should also mention that I've also tried to do this with ljpeg version 9 (just to see what would happen), and then I was experiencing this error:

Code: Select all

JPEG parameter struct mismatch: library thinks size is 632, caller expects 664
This seems to imply there's still some sort of linking error, but I can't be positive. Any help would be really appreciated.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Incorrect JPEG Version

Post by fmw42 »

Wrong JPEG library version: library is 90, caller expects 80
This usually happens (as I understand it) when you have multiple versions of libjpeg on your system and something else is linked to the older version and IM is looking for the newer version. Typically it goes away if you can find what is looking for the older versions, remove the older versions, compile the newer version (9) and then recompile whatever was using the older versions as well as IM.

Do you have multiple version of IM perhaps (one using an older libjpeg and the other trying to compile against the newer ligjpeg)

I do not know much about windows and how to deal with this or static versions.
vhmth
Posts: 13
Joined: 2014-02-06T15:49:55-07:00
Authentication code: 6789

Re: Incorrect JPEG Version

Post by vhmth »

That was my understanding of the error as well. Something is being linked incorrectly somewhere. However, I do not (to the best of my knowledge) know of libjpeg or imagemagick being installed on my computer (which is a Mac not a Windows machine). Also, if you look at the output of "make" that I posted above, it seems to be looking for libs in the correct place. If I remove the libjpeg I compiled, it does complain about not being able to find libjpeg.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Incorrect JPEG Version

Post by fmw42 »

try

find /usr | grep "libjpeg"

if you loaded your delegates manually

or

find /opt | grep "libjpeg"

if you loaded your delegates from MacPorts

Look for things like

/opt/local/lib/libjpeg.9.dylib

The 9 means version 9 of libjpeg. See if you have versions with 6 or 8.

I am on a Mac also and have had this problem a long time ago. It was some other delegate that was linked to an older version of libjpeg, if I recall correctly.

Currently I load my delegates from MacPorts but compile IM from source.
vhmth
Posts: 13
Joined: 2014-02-06T15:49:55-07:00
Authentication code: 6789

Re: Incorrect JPEG Version

Post by vhmth »

I will try to see if I can remove the other delegates, but, based on the delegates output of the make step, I only have:

Code: Select all

 DELEGATES       = mpeg jpeg zlib
It's picking up on zlib and mpeg from system-installed libs. Is there a way to tell ImageMagick to not look in /usr/lib or /usr/local/lib? This is the output from MAKE for the LDFLAGS and MAGICK_LDFLAGS fields:

Code: Select all

  LDFLAGS         = -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg/.libs -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/magick -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/wand
  MAGICK_LDFLAGS  = -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/lib -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg/.libs -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/magick -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/wand
So I assumed that it wasn't looking in /usr/lib or /usr/local/lib (obviously assumed incorrectly :-P).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Incorrect JPEG Version

Post by fmw42 »

What did you get from the "find" commands I asked you to run?

convert -version

should tell you what delegates you have installed if you are running a current version of IM. Otherwise run

convert -list configure

and look at the line starting with Delegates.

You can find where IM resides by

type -a convert

or

where convert
vhmth
Posts: 13
Joined: 2014-02-06T15:49:55-07:00
Authentication code: 6789

Re: Incorrect JPEG Version

Post by vhmth »

Results of find:

Code: Select all

/usr/local/bin/cjpeg
/usr/local/bin/djpeg
/usr/local/bin/jpegtran
/usr/local/include/jpeglib.h
/usr/local/Library/Aliases/libjpeg
/usr/local/Library/Aliases/libjpeg-turbo
/usr/local/Library/Formula/jpeg-turbo.rb
/usr/local/Library/Formula/jpeg.rb
/usr/local/Library/Formula/jpeg2ps.rb
/usr/local/Library/Formula/jpeginfo.rb
/usr/local/Library/Formula/jpegoptim.rb
/usr/local/Library/Formula/mjpegtools.rb
/usr/local/Library/Formula/openjpeg.rb
/usr/local/Library/Formula/recoverjpeg.rb
/usr/local/share/man/man1/cjpeg.1
/usr/local/share/man/man1/djpeg.1
/usr/local/share/man/man1/jpegtran.1
/usr/share/file/magic/jpeg
/usr/share/man/mann/img-jpeg.n
/usr/share/man/mann/jpeg.n
Results of convert -version:

Code: Select all

Delegates: jpeg zlib
Results of convert -list configure

Code: Select all

Path: /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/lib/ImageMagick-6.8.7//config-Q16/configure.xml

Name           Value
-------------------------------------------------------------------------------
CC             clang
CFLAGS         -Wall -fexceptions -D_FORTIFY_SOURCE=0 -D_THREAD_SAFE -pthread -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
CODER_PATH     /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/lib/ImageMagick-6.8.7/modules-Q16/coders
CONFIGURE      ./configure  '--enable-static' '--disable-shared' '--enable-delegate-build' '--disable-installed' '--prefix=/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick' '--without-bzlib' '--without-djvu' '--without-dps' '--without-fftw' '--without-fpx' '--without-fontconfig' '--without-freetype' '--without-jbig' '--without-jp2' '--without-lcms' '--without-lcms2' '--without-lqr' '--without-lzma' '--without-magick-plus-plus' '--without-openexr' '--without-pango' '--without-perl' '--without-tiff' '--without-webp' '--without-xml' '--without-zlib' 'CC=clang' 'CFLAGS=' 'LDFLAGS=-L./' 'CXX=clang++' 'CXXFLAGS='
CONFIGURE_PATH /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/etc/ImageMagick-6/
COPYRIGHT      Copyright (C) 1999-2014 ImageMagick Studio LLC
CPPFLAGS       -I/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/include/ImageMagick-6
CXX            clang++
CXXFLAGS       -D_THREAD_SAFE -pthread
DEFS           -DHAVE_CONFIG_H
[b]DELEGATES      mpeg jpeg zlib[/b]
DISTCHECK_CONFIG_FLAGS 'CC=clang' 'CFLAGS=' 'CXX=clang++' 'LDFLAGS=-L./' --disable-deprecated --disable-installed --with-quantum-depth=16 --with-umem=no --with-bzlib=no --with-zlib=no --with-autotrace=no --with-dps=no --with-djvu=no --with-fftw=no --with-fpx=no --with-fontconfig=no --with-freetype=no --with-gslib=no --with-fontpath= --with-gvc=no --with-jp2=no --with-lcms=no --with-lcms2=no --with-lqr=no --with-lzma=no --with-mupdf=no --with-openexr=no --with-pango=no --with-rsvg=no --with-tiff=no --with-webp=no --with-wmf=no --with-xml=no --with-perl=no
DOCUMENTATION_PATH /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/share/doc/ImageMagick-6
EXEC-PREFIX    /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick
EXECUTABLE_PATH /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/bin
FEATURES       DPC
FILTER_PATH    /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/lib/ImageMagick-6.8.7/modules-Q16/filters
HOST           x86_64-apple-darwin13.0.0
INCLUDE_PATH   /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/include/ImageMagick-6
LDFLAGS        -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/lib -L./ -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg/.libs -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/jpeg -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/magick -L/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/ImageMagick-6.8.7-8/wand
LIB_VERSION    0x687
LIB_VERSION_NUMBER 6,8,7,8
LIBRARY_PATH   /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/lib/ImageMagick-6.8.7
LIBS           -ljpeg -lz -lm
NAME           ImageMagick
PCFLAGS        -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
PREFIX         /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick
QuantumDepth   16
RELEASE_DATE   2014-02-06
SHARE_PATH     /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/share/ImageMagick-6
SHAREARCH_PATH /Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/lib/ImageMagick-6.8.7/config-Q16
SVN_REVISION   13853
TARGET_CPU     x86_64
TARGET_OS      darwin13.0.0
TARGET_VENDOR  apple
VERSION        6.8.7
WEBSITE        http://www.imagemagick.org

Path: [built-in]

Name           Value
-------------------------------------------------------------------------------
FEATURES       
NAME           ImageMagick
QuantumDepth   16
Location of convert:

Code: Select all

/Users/vinay/Desktop/Code/upthere/3rdparty/ImageMagick/build/ImageMagick/bin
Although, as I mentioned earlier, I am only interesting in using the libMagickCore and libMagickWand static files. I must compile libjpeg as well as any delegate libs. I realized there were some libjpeg files from the find command. This was happening on the install step of libjpeg, but I fixed that issue (forgot to set the prefix flag when configuring libjpeg), and the incorrect jpeg version issue persists (I made sure to remove the static files and headers).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Incorrect JPEG Version

Post by fmw42 »

I don't see anything odd there. So I am at a loss to help further.
vhmth
Posts: 13
Joined: 2014-02-06T15:49:55-07:00
Authentication code: 6789

Re: Incorrect JPEG Version

Post by vhmth »

To keep you guys posted, I have successfully built and linked IM with libpng and zlib (compiled from source). I have also tried the following:

1. Tried compiling on another machine with basically nothing on it.
2. Updated my IM lib itself.
3. Updated libjpeg to v9.

Updating libjpeg to v9 seems to have gotten rid of the mismatch error, but now I get the following error:

Code: Select all

JPEG parameter struct mismatch: library thinks size is 632, caller expects 664
Which leads me to believe there is still a linking issue. I'm still completely at a loss as to what to do next.
vhmth
Posts: 13
Joined: 2014-02-06T15:49:55-07:00
Authentication code: 6789

Re: Incorrect JPEG Version

Post by vhmth »

I figured out the issue. It was, as the error suggested, a different version of libjpeg being linked. In case people are curious as to what happened, let me set the landscape of the situation:

1. We build ImageMagick with its delegate libraries.
2. We build FreeImage with its own delegate libraries.

At this point, there is no complaining since these are never linked together. However, when we link our own code against IM and FreeImage, we get symbol clashing since FreeImage has its own flavor of libjpeg, libpng, etc. So, even if you were to build the same version of libjpeg from http://libjpeg.sourceforge.net/ that matches with FreeImage's version, you will get conflicts. That is, you cannot simply share a delegate lib between FreeImage and ImageMagick.

The solution we came up with was to remove FreeImage overall from our build system. However, if someone really needs to use both FreeImage and ImageMagick, you can localize the delegate library symbols before creating a static or dynamic library with objtool so they do not clash between the two libraries. This is, in practice with a complicated build system, a rather large pain in the ass as it now requires you to keep a running list of libraries whose symbols must be localized.
Post Reply