4

How do I install BPG (Better Portable Graphics) on Linux Mint 17? I downloaded the tar.gz file from Fabrice Bellard's website. The ReadMe file says,

Edit the Makefile to change the compile options (the default compile options should be OK for Linux). Type 'make' to compile and 'make install' to install the compiled binaries.

I didn't edit the Makefile. I opened the terminal in the directory and ran make. It returned the following error:

gcc -g -Wl,--gc-sections -o bpgdec bpgdec.o libbpg.a -lpng -lrt -lm -lpthread
bpgdec.o: In function `png_save':
/home/ghort/Downloads/libbpg-0.9.5/bpgdec.c:118: undefined reference to 
  `png_set_longjmp_fn'
collect2: error: ld returned 1 exit status
make: *** [bpgdec] Error 1

I think I read elsewhere that I need to install libpng16 experimental, but I'm not sure.

6
+50

libbpg depends on version 1.6 of the PNG library, which you cannot install with apt-get on Linux Mint 17. This library is incompatible with libpng12 and needs to be installed from source (I used version 1.6.16)

The additional complication is that if you install PNG 1.6 the make of libbpg still uses libpng12-dev even if you configure PNG 1.6 with configure --prefix=/usr. And you cannot just deinstall libpng12-dev as libsdl-image1.2-dev and libsdl1.2-dev depend on it, and those are needed for compiling libbpg as well.

You could probably also download and compile the libsdl-image and libsdl1 sources and not install their -dev packages. I did not follow that route, I just temporarily removed the files (not the package) from libpng12-dev and reinstalled them after I was done (you should be able to copy and paste this on Linux Mint 17):¹

# install dev packages needed 
sudo apt-get install -y libsdl-image1.2-dev libsdl1.2-dev libjpeg8-dev
#### temporarily remove the files from the libpng12 package
# this gives error messages on the directories (that cannot be removed this
# way, which can be ignored.
sudo rm $(dpkg -L libpng12-dev)

# download, configure, make and make install PNG 1.6
wget -O libpng-1.6.16.tar.xz 'http://downloads.sourceforge.net/project/libpng/libpng16/1.6.16/libpng-1.6.16.tar.xz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Flibpng%2Ffiles%2Flibpng16%2F1.6.16%2F&ts=1424607004&use_mirror=garr'
tar xf libpng-1.6.16.tar.xz
pushd libpng-1.6.16
./configure --prefix=/usr
make -j
sudo make install
popd

# download, make and make install BPG
wget http://bellard.org/bpg/libbpg-0.9.5.tar.gz
tar xf libbpg-0.9.5.tar.gz
pushd libbpg-0.9.5
make -j
sudo make install
popd

# reinstall libpng12-dev
sudo apt-get install --reinstall libpng12-dev

Of course it would be more appropriate to install PNG 1.6 in parallel to libpng12-dev and adapt the sources of libbpg, but since you don't recompile the BPG library on a regular basis, IMO this kludge is acceptable.


¹ You could also try and build libpng16-dev, but installing that might just remove the -dev packages depending on libpng12-dev, I did not try that.

  • Thank you. I followed your directions. Two things to note: the command sudo rm $(dpkg -L libpng12-dev) didn't work, returning the error that I don't have permission. I went ahead with executing the subsequent steps and I was able to install. I also had to use one last command: sudo ldconfig /usr/local/lib I received the error: error while loading shared libraries: libMagickCore.so.4 I found the solution here to this – user8547 Feb 22 '15 at 23:03
  • I had to use the command sudo ldconfig /usr/local/lib because I was getting the error error while loading shared libraries: libMagickCore.so.4. I found the solution here. – user8547 Feb 22 '15 at 23:10
  • 1
    @user8547 I should have warned about the sudo rm it tries to rm directories but can't which is fine, as they don't interfere. – Anthon Feb 22 '15 at 23:23
  • Incidentally, to clarify my solution to error while loading shared libraries: libMagickCore.so.4. That was an error I received after installing the latest ImageMagick release, so it's not related to the BPG installation. – user8547 Feb 22 '15 at 23:28
4

It's better not to change the officialy installed package libpng12-dev but rather to indicate in the Makefile from libbpg where to find libpng 1.6

So I modify the Anthon's solution :

# install dev packages needed 
sudo apt-get install -y libsdl-image1.2-dev libsdl1.2-dev libjpeg8-dev

# download, configure, make and make install PNG 1.6 (You coul find a newer version like 1.16.18 for me)
wget -O libpng-1.6.16.tar.xz 'http://downloads.sourceforge.net/project/libpng/libpng16/1.6.16/libpng-1.6.16.tar.xz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Flibpng%2Ffiles%2Flibpng16%2F1.6.16%2F&ts=1424607004&use_mirror=garr'
tar xf libpng-1.6.16.tar.xz
pushd libpng-1.6.16
./configure
make -j
sudo make install
#### The installation will take place in /usr/local by default and it's ok !
popd

# download, make and make install BPG
wget http://bellard.org/bpg/libbpg-0.9.5.tar.gz
tar xf libbpg-0.9.5.tar.gz
pushd libbpg-0.9.5

#### edit Makefile and insert the two following directive :
# "CFLAGS+=-I/usr/local/include" after the line CFLAGS+=-I.
# "LDFLAGS+=-L /usr/local/lib" before the line CFLAGS+=-g

make -j
sudo make install
popd

That's all folks !

4

The other answers on here are great, but I wanted to create a completely automated installation script.

#!/bin/bash

sudo apt-get install -y cmake yasm libjpeg-dev libsdl-image1.2-dev libsdl1.2-dev

pushd /tmp
    wget -O libpng-1.6.21.tar.xz "https://downloads.sourceforge.net/project/libpng/libpng16/older-releases/1.6.21/libpng-1.6.21.tar.gz?ts=$(date +%s)"
    tar xf libpng-1.6.21.tar.xz
    pushd libpng-1.6.21
        ./configure
        make -j
        sudo make install
    popd
    git clone "https://github.com/mirrorer/libbpg"
    pushd libbpg
        patch <<EOF
--- Makefile    2016-02-03 11:43:37.883142427 -0500
+++ Makefile    2016-02-03 11:44:20.867143492 -0500
@@ -41,6 +41,7 @@
 CFLAGS:=-Os -Wall -MMD -fno-asynchronous-unwind-tables -fdata-sections -ffunction-sections -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -fomit-frame-pointer
 CFLAGS+=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT
 CFLAGS+=-I.
+CFLAGS+=-I/usr/local/include
 CFLAGS+=-DCONFIG_BPG_VERSION=\"\$(shell cat VERSION)\"
 ifdef USE_JCTVC_HIGH_BIT_DEPTH
 CFLAGS+=-DRExt__HIGH_BIT_DEPTH_SUPPORT
@@ -59,6 +60,7 @@
 else
 LDFLAGS+=-Wl,--gc-sections
 endif
+LDFLAGS+=-L /usr/local/lib
 CFLAGS+=-g
 CXXFLAGS=\$(CFLAGS)
EOF
        make -j
        sudo make install
    popd
popd
sudo ldconfig  # Required for bpgenc to find libpng16.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.