0%

compile and use libjpeg-turbo on ubuntu 16.04

Series

Guide

build requirements

  • autoconf 2.56 or later
  • automake 1.7 or later
  • libtool 1.4 or later
  • NASM 2.13 x86-64
  • libjpeg-turbo latest

install tools

1
sudo apt-get install autoconf automake libtool

compile nasm

1
2
3
4
5
wget http://www.nasm.us/pub/nasm/releasebuilds/2.13.03/nasm-2.13.03.tar.gz
cd nasm
./configure
make -j8
sudo make install

this will install nasm to /usr/local/bin/nasm

compile libjpeg

We can not use cmake to build libjpeg on linux.
Platform not supported by this build system. Use autotools instead.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
git clone https://github.com/libjpeg-turbo/libjpeg-turbo.git

cd libjpeg-turob

# generate configure
autoreconf -fiv

# exec-prefix=/usr/local/ for /bin and /lib
# prefix=/usr/local/include/libjpegturbo for /include
./configure --exec-prefix=/usr/local --prefix=/usr/local/include/libjpegturbo --with-jpeg8 --disable-static

make -j8
make test
sudo make install

libjpegturbo-config.cmake

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# - Try to find LIBJPEGTURBO
#
# The following variables are optionally searched for defaults
# LIBJPEGTURBO_ROOT_DIR: Base directory where all LIBJPEGTURBO components are found
#
# The following are set after configuration is done:
# LIBJPEGTURBO_FOUND
# LIBJPEGTURBO_INCLUDE_DIRS
# LIBJPEGTURBO_LIBRARIES
# LIBJPEGTURBO_LIBRARYRARY_DIRS

include(FindPackageHandleStandardArgs)

set(LIBJPEGTURBO_ROOT_DIR "" CACHE PATH "Folder contains mysqlcppconn")

if(WIN32)
find_path(LIBJPEGTURBO_INCLUDE_DIR turbojpeg.h
PATHS ${LIBJPEGTURBO_ROOT_DIR})
else()
find_path(LIBJPEGTURBO_INCLUDE_DIR turbojpeg.h
PATHS ${LIBJPEGTURBO_ROOT_DIR})
endif()

if(MSVC)
find_library(LIBJPEGTURBO_LIBRARY_RELEASE turbojpeg
PATHS ${LIBJPEGTURBO_ROOT_DIR}
PATH_SUFFIXES Release)

find_library(LIBJPEGTURBO_LIBRARY_DEBUG turbojpeg
PATHS ${LIBJPEGTURBO_ROOT_DIR}
PATH_SUFFIXES Debug)

set(LIBJPEGTURBO_LIBRARY optimized ${LIBJPEGTURBO_LIBRARY_RELEASE} debug ${LIBJPEGTURBO_LIBRARY_DEBUG})
else()
find_library(LIBJPEGTURBO_LIBRARY turbojpeg
PATHS ${LIBJPEGTURBO_ROOT_DIR}
PATH_SUFFIXES lib lib64)
endif()

find_package_handle_standard_args(LIBJPEGTURBO DEFAULT_MSG LIBJPEGTURBO_INCLUDE_DIR LIBJPEGTURBO_LIBRARY)

if(LIBJPEGTURBO_FOUND)
set(LIBJPEGTURBO_INCLUDE_DIRS ${LIBJPEGTURBO_INCLUDE_DIR})
set(LIBJPEGTURBO_LIBRARIES ${LIBJPEGTURBO_LIBRARY})
message(STATUS "Found mysqlcppconn (include: ${LIBJPEGTURBO_INCLUDE_DIR}, library: ${LIBJPEGTURBO_LIBRARY})")
mark_as_advanced(LIBJPEGTURBO_ROOT_DIR LIBJPEGTURBO_LIBRARY_RELEASE LIBJPEGTURBO_LIBRARY_DEBUG
LIBJPEGTURBO_LIBRARY LIBJPEGTURBO_INCLUDE_DIR)
endif()

copy libjpegturbo-config.cmake to /usr/local/lib/cmake/libjpegturbo/

1
2
sudo mkdir -p /usr/local/lib/cmake/libjpegturbo/
sudo cp libjpegturbo-config.cmake /usr/local/lib/cmake/libjpegturbo/

CMakeLists.txt

1
2
3
find_package(LIBJPEGTURBO REQUIRED)
include_directories(${LIBJPEGTURBO_INCLUDE_DIRS})
target_link_libraries (example_jpeg ${LIBJPEGTURBO_LIBRARIES})

Reference

History

  • 20180223: created.