Blog 1

Random Talk on Random Thoughts

Installed Jpegtran From Source With MinGW32

| Comments |

Background

To reduce the bandwidth usage while viewing pictures in this blog, I’ve already run OptiPNG on PNG pictures in my new posts.1 For JPEG files optimization, Google developers suggest jpegoptim or jpegtran.2 Since the first tool isn’t available for M$ Win* 7, I installed the second one. I couldn’t find a compiled version of the software, so I had to compile it from source code.

Problem

Since there’re too many words following the instructions for a *nix machine below the table of contents in install.txt, I tried installing it with Make like *nix, so that the installation could be finished in four simple commands: ./configure, make, make test and make install. The output of the first command was fine.3

Unluckily, I got trouble when I moved on to the next command.

$ make
c:/Temp/gnuwin32/bin/make  all-am
c:/Temp/gnuwin32/bin/make: Interrupt/Exception caught (code = 0xc00000fd, addr =
 0x4227d3)
make: *** [all] Error 255

Solution

I googled “make interrupt/exception caught” and read a Super User question at the top of the list of search results.4 Luckily, the code and addr in the chosen response matched what I’d got above. I therefore jumped to the last paragraph and added the line at the top of the generated Makefile.

SHELL=C:/Windows/System32/cmd.exe

I then tried issuing make for another time, and failed again.

$ make
make  all-am
make[1]: Entering directory `C:/Users/Owner/Downloads/jpeg-9a'
"  CC      " jaricom.lo;C:/Windows/System32/cmd.exe ./libtool --silent --tag=CC
  --mode=compile gcc -std=gnu99 -DHAVE_CONFIG_H -I.     -g -O2 -MT jaricom.lo -M
D -MP -MF .deps/jaricom.Tpo -c -o jaricom.lo jaricom.c
mv: cannot stat '.deps/jaricom.Tpo': No such file or directory
make[1]: *** [jaricom.lo] Error 1
make[1]: Leaving directory `C:/Users/Owner/Downloads/jpeg-9a'
make: *** [all] Error 2

I tried doing the same thing in M$’s Command Prompt, but got the same errors. I also tried following the second answer and adding PATH= below the first line of Makefile, and Make still threw errors and said that rm wasn’t an internal or external command. This caused me to give up on this answer.

I learnt from past experience and performed a make clean. This failed unexpectedly. I copied some words in the error message and googled “make clean windows list is not recognized as an internal or external command”, and viewed some irrelevant websites.

I then re-read the first answer to that Super User question, and found the cause of the problem. I quickly saved the original PATH environment varible in Control Panel into a TXT file, duplicate that TXT file, and use gVim to replace all instances of Program Files (x86), Program Files and Intel(R) Management Engine Components by three different strings without ‘(‘ and ‘)’, for example, PROGRA~1, PROGRA~2 and intel~1.

I re-ran make in both Git Bash and M$ Command Prompt, and received the same error again. I suddenly realized that I should try MSYS, the shell released by the same group of developers of MinGW. Finally, the remaining three commands worked well.5

Lessons learnt

I tried googling sample jpegtran commands, but the search wasn’t effective. From this, I’ve learnt to read the official README and other help files accompanying the source files.

I used > in jpegtran commands, and strange images were produced. I once thought that an compilation error occured. However, the test images test*.* in the directory which contained the source files and compiled binary files were OK. By looking at the “Date Modified” in a file browser, I guessed that the test images generated by the program were made by make test. I browsed Makefile again, and finally got the correct syntax for optimizing JPEG images.

Finally, I think that the new lossless scaling feature works in my compiled version of jpegtran, though I can’t see the output pictures.


Bash’s output for ./configure

Luckily, this command worked on my laptop.

$ ./configure
checking build system type... i686-pc-mingw32
checking host system type... i686-pc-mingw32
checking target system type... i686-pc-mingw32
checking for a BSD-compatible install... ./install-sh -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for gcc option to accept ISO C99... -std=gnu99
checking for gcc -std=gnu99 option to accept ISO Standard C... (cached) -std=gnu
99
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking whether make sets $(MAKE)... (cached) yes
checking whether ln -s works... no, using cp -pR
checking for ar... ar
checking the archiver (ar) interface... ar
checking if LD -Wl,--version-script works... yes
checking for function prototypes... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking stddef.h usability... yes
checking stddef.h presence... yes
checking for stddef.h... yes
checking for stdlib.h... (cached) yes
checking locale.h usability... yes
checking locale.h presence... yes
checking for locale.h... yes
checking for string.h... (cached) yes
checking for size_t... yes
checking for type unsigned char... yes
checking for type unsigned short... yes
checking for type void... yes
checking for an ANSI C-conforming const... yes
checking for inline... __inline__
checking for broken incomplete types... ok
checking for short external names... ok
checking to see if char is signed... yes
checking to see if right shift is signed... yes
checking to see if fopen accepts b spec... yes
checking for as... as
checking for dlltool... dlltool
checking for objdump... objdump
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc -std=gnu99... c:/mingw/mingw32/bin/ld.exe
checking if the linker (c:/mingw/mingw32/bin/ld.exe) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /c/MinGW/bin/nm
checking the name lister (/c/MinGW/bin/nm) interface... BSD nm
checking the maximum length of command line arguments... 8192
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert i686-pc-mingw32 file names to i686-pc-mingw32 format...
func_convert_file_msys_to_w32
checking how to convert i686-pc-mingw32 file names to toolchain format... func_c
onvert_file_msys_to_w32
checking for c:/mingw/mingw32/bin/ld.exe option to reload object files... -r
checking for objdump... (cached) objdump
checking how to recognize dependent libraries... file_magic ^x86 archive import|
^x86 DLL
checking for dlltool... (cached) dlltool
checking how to associate runtime and link libraries... func_cygming_dll_for_imp
lib
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /c/MinGW/bin/nm output from gcc -std=gnu99 object... o
k
checking for sysroot... no
checking for mt... no
checking if : is a manifest tool... no
checking for dlfcn.h... no
checking for objdir... .libs
checking if gcc -std=gnu99 supports -fno-rtti -fno-exceptions... no
checking for gcc -std=gnu99 option to produce PIC... -DDLL_EXPORT -DPIC
checking if gcc -std=gnu99 PIC flag -DDLL_EXPORT -DPIC works... yes
checking if gcc -std=gnu99 static flag -static works... yes
checking if gcc -std=gnu99 supports -c -o file.o... yes
checking if gcc -std=gnu99 supports -c -o file.o... (cached) yes
checking whether the gcc -std=gnu99 linker (c:/mingw/mingw32/bin/ld.exe) support
s shared libraries... yes
checking whether -lc should be explicitly linked in... yes
checking dynamic linker characteristics... Win32 ld.exe
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking libjpeg version number... 10:0:1
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating jconfig.h
config.status: executing depfiles commands
config.status: executing libtool commands

Switched to MSYS

The installation was successful in MSYS.

$ make clean
rm -f cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe
rm -f cjpeg djpeg jpegtran rdjpgcom wrjpgcom
test -z "testout.ppm testout.bmp testout.jpg testoutp.ppm testoutp.jpg testoutt.
jpg" || rm -f testout.ppm testout.bmp testout.jpg testoutp.ppm testoutp.jpg test
outt.jpg
test -z "libjpeg.la" || rm -f libjpeg.la
rm -f ./so_locations
rm -rf .libs _libs
rm -f *.o
rm -f *.lo

$ make
make  all-am
make[1]: Entering directory `/c/Users/Owner/Downloads/jpeg-9a'
  CC       jaricom.lo
  CC       jcapimin.lo
  CC       jcapistd.lo
  CC       jcarith.lo
  CC       jccoefct.lo
  CC       jccolor.lo
  CC       jcdctmgr.lo
  CC       jchuff.lo
  CC       jcinit.lo
  CC       jcmainct.lo
  CC       jcmarker.lo
  CC       jcmaster.lo
  CC       jcomapi.lo
  CC       jcparam.lo
  CC       jcprepct.lo
  CC       jcsample.lo
  CC       jctrans.lo
  CC       jdapimin.lo
  CC       jdapistd.lo
  CC       jdarith.lo
  CC       jdatadst.lo
  CC       jdatasrc.lo
  CC       jdcoefct.lo
  CC       jdcolor.lo
  CC       jddctmgr.lo
  CC       jdhuff.lo
  CC       jdinput.lo
  CC       jdmainct.lo
  CC       jdmarker.lo
  CC       jdmaster.lo
  CC       jdmerge.lo
  CC       jdpostct.lo
  CC       jdsample.lo
  CC       jdtrans.lo
  CC       jerror.lo
  CC       jfdctflt.lo
  CC       jfdctfst.lo
  CC       jfdctint.lo
  CC       jidctflt.lo
  CC       jidctfst.lo
  CC       jidctint.lo
  CC       jquant1.lo
  CC       jquant2.lo
  CC       jutils.lo
  CC       jmemmgr.lo
  CC       jmemnobs.lo
  CCLD     libjpeg.la
  CC       cjpeg.o
  CC       rdppm.o
  CC       rdgif.o
  CC       rdtarga.o
  CC       rdrle.o
  CC       rdbmp.o
  CC       rdswitch.o
  CC       cdjpeg.o
  CCLD     cjpeg.exe
  CC       djpeg.o
  CC       wrppm.o
  CC       wrgif.o
  CC       wrtarga.o
  CC       wrrle.o
  CC       wrbmp.o
  CC       rdcolmap.o
  CCLD     djpeg.exe
  CC       jpegtran.o
  CC       transupp.o
  CCLD     jpegtran.exe
  CC       rdjpgcom.o
  CCLD     rdjpgcom.exe
  CC       wrjpgcom.o

$ make test
rm -f testout*
./djpeg -dct int -ppm -outfile testout.ppm  ./testorig.jpg
./djpeg -dct int -bmp -colors 256 -outfile testout.bmp  ./testorig.jpg
./cjpeg -dct int -outfile testout.jpg  ./testimg.ppm
./djpeg -dct int -ppm -outfile testoutp.ppm ./testprog.jpg
./cjpeg -dct int -progressive -opt -outfile testoutp.jpg ./testimg.ppm
./jpegtran -outfile testoutt.jpg ./testprog.jpg
cmp ./testimg.ppm testout.ppm
cmp ./testimg.bmp testout.bmp
cmp ./testimg.jpg testout.jpg
cmp ./testimg.ppm testoutp.ppm
cmp ./testimgp.jpg testoutp.jpg
cmp ./testorig.jpg testoutt.jpg

$ make install
make[1]: Entering directory `/c/Users/Owner/Downloads/jpeg-9a'
 /bin/mkdir -p '/usr/local/lib'
 /bin/sh ./libtool   --mode=install ./install-sh -c   libjpeg.la '/usr/local/lib
'
libtool: install: ./install-sh -c .libs/libjpeg.dll.a /usr/local/lib/libjpeg.dll
.a
libtool: install: base_file=`basename libjpeg.la`
libtool: install:  dlpath=`/bin/sh 2>&1 -c '. .libs/'libjpeg.la'i; echo libjpeg-
9.dll'`
libtool: install:  dldir=/usr/local/lib/`dirname ../bin/libjpeg-9.dll`
libtool: install:  test -d /usr/local/lib/../bin || mkdir -p /usr/local/lib/../b
in
libtool: install:  ./install-sh -c .libs/libjpeg-9.dll /usr/local/lib/../bin/lib
jpeg-9.dll
libtool: install:  chmod a+x /usr/local/lib/../bin/libjpeg-9.dll
libtool: install:  if test -n '' && test -n 'strip --strip-unneeded'; then eval
'strip --strip-unneeded /usr/local/lib/../bin/libjpeg-9.dll' || exit 0; fi
libtool: install: ./install-sh -c .libs/libjpeg.lai /usr/local/lib/libjpeg.la
libtool: install: ./install-sh -c .libs/libjpeg.a /usr/local/lib/libjpeg.a
libtool: install: chmod 644 /usr/local/lib/libjpeg.a
libtool: install: ranlib /usr/local/lib/libjpeg.a
 /bin/mkdir -p '/usr/local/bin'
  /bin/sh ./libtool   --mode=install ./install-sh -c cjpeg.exe djpeg.exe jpegtra
n.exe rdjpgcom.exe wrjpgcom.exe '/usr/local/bin'
libtool: install: ./install-sh -c .libs/cjpeg.exe /usr/local/bin/cjpeg.exe
libtool: install: ./install-sh -c .libs/djpeg.exe /usr/local/bin/djpeg.exe
libtool: install: ./install-sh -c .libs/jpegtran.exe /usr/local/bin/jpegtran.exe

libtool: install: ./install-sh -c .libs/rdjpgcom.exe /usr/local/bin/rdjpgcom.exe

libtool: install: ./install-sh -c .libs/wrjpgcom.exe /usr/local/bin/wrjpgcom.exe

/bin/sh /c/Users/Owner/Downloads/jpeg-9a/install-sh -d /usr/local/include
./install-sh -c -m 644 jconfig.h /usr/local/include/jconfig.h
 /bin/mkdir -p '/usr/local/include'
 ./install-sh -c -m 644 jerror.h jmorecfg.h jpeglib.h '/usr/local/include'
 /bin/mkdir -p '/usr/local/share/man/man1'
 ./install-sh -c -m 644 cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 wrjpgcom.1 '/usr/l
ocal/share/man/man1'
make[1]: Leaving directory `/c/Users/Owner/Downloads/jpeg-9a'

Comments