[back to Index]

LibRaw Compilation and Installation

LibRaw is distributed in the form of source codes. For further use, they should be compiled (and, if desired, placed into system folders with libraries and include-files).

Unix Systems (FreeBSD, Linux, Mac OS X)

To build the library, you will need a working C++ compiler (gcc 3+ and clang 2+ are OK) and the make utility.

Additional libraries (optional):

LibRaw has been tested on 32- and 64-bit Unix systems working on x86- (and AMD64-) compatible processors. Building and work on other architectures have not been tested.

Compilation of Library and Examples

Unpack the downloaded distribution package.

        tar xzvf LibRaw-X.YY.tar.gz

For GitHub downloads (clones), perform ./configure script generation via

        autoreconf --install

Go to LibRaw directory and run ./configure and make:

cd LibRaw-X.YY
./configure # with optional args
make
    

As a result, you will compile

In the current version, only static libraries are built:

Build via provided Makefiles

Several makefiles provided to simplify basic build process:

To build via provided Makefile: edit it to adjust compilation flag and use make/gmake/nmake -f Makefile

Build time defines

File size/memory limits:

Other build-time parameters (defines)

Build parameters

./configure script have some non-standard parameters:

--enable-openmp
--disable-openmp
Enable/disable OpenMP support if compiler supports it. OpenMP is enabled by default.
--enable-lcms
--disable-lcms
Enable/disable LCMS color engine support. If enabled, ./configure will try to find lcms library. Both LCMS-1.x and LCMS-2.x are supported LCMS support is enabled by default
--enable-examples
--disable-examples
Enables/disables examples compilation and installation. Enabled by default

Installation and Usage

To install the library, run

    sudo make install
    

It will place the libraries in /usr/local/lib, the include-files in /usr/local/include (subfolder of libraw) and LibRaw samples to /usr/local/bin. You can override installation path by using ./configure script.
To use LibRaw, add the following parameters to the compiler call (when building your own projects):

macOS: Building with OpenMP

On macOS, building with OpenMP requires libomp. The Homebrew libomp formula is installed as keg-only, so:

You must explicitly point the build to the libomp include and library paths using brew --prefix.

1. Install libomp:

    brew install libomp

2. Configure environment and build:

    export CFLAGS="-I$(brew --prefix libomp)/include"
    export CXXFLAGS="$CFLAGS"
    export LDFLAGS="-framework CoreFoundation -framework Carbon -L$(brew --prefix libomp)/lib -lomp"

    autoreconf --install --force # if building from repository sources
    ./configure --enable-openmp
    

In the configure output, you should see a line similar to:

    checking for OpenMP flag of C compiler... -Xpreprocessor -fopenmp

3. Build:

    make -j10
    

macOS: Building Universal Binary with OpenMP

This section describes how to build a Universal Binary (arm64 + x86_64) with OpenMP.

1. Build and save the arm64 libraries

First build the project normally (as above) and store the resulting static libraries:

    cp lib/.libs/libraw.a libraw.a.arm64
    cp lib/.libs/libraw_r.a libraw_r.a.arm64
    

2. Install Intel Homebrew and libomp (x86_64)

You also need an x86_64 toolchain via Intel Homebrew.

Install Intel Homebrew:

    arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    

Ensure the Intel Homebrew prefix (/usr/local) is first in PATH for this terminal session so that any subsequent call to brew invokes specifically the Intel installation:

    export PATH=/usr/local/bin:$PATH
    

Install libomp:

    brew install libomp
    

Confirm that it's indeed the x86_64 version that's being found and reported by brew:

    brew --prefix libomp
    

It should return /usr/local/opt/libomp.

Note: The Intel Homebrew installation works correctly even when invoked from an Apple Silicon terminal.

Note: building sample apps will fail because on macOS, OpenMP requires different flags for compile vs link and libtool has no native understanding of Apple OpenMP semantics. Thus if you encounter clang++: error: unsupported option '-fopenmp' when building sample apps, copy-paste the linker invocation from the make output and remove the trailing -fopenmp flag.

3. Configure and build the x86_64 libraries

Configure for x86_64 with OpenMP:

    export CFLAGS="-arch x86_64 -I$(brew --prefix libomp)/include"
    export CXXFLAGS="$CFLAGS"
    export LDFLAGS="-framework CoreFoundation -framework Carbon -L$(brew --prefix libomp)/lib -lomp"
    ./configure --enable-openmp
    

Check the configure output again to confirm OpenMP is detected.

Note: these are the same configure options and compiler flags as before, but including -arch x86_64 and of course it's the Intel version of Homebrew that's now substituting paths to libomp.

Build:

    make -j10
    

Note: Compiling an x86_64 binary from an Apple Silicon terminal using an arm64 host works fine on macOS as long as you pass the correct -arch and use the x86_64 toolchain and libraries.

Verify that the binary built is indeed Intel:

    lipo -info lib/.libs/libraw.a
    

You should see:

    Non-fat file: lib/.libs/libraw.a is architecture: x86_64
    

Save the Intel build:

    cp lib/.libs/libraw.a libraw.a.x86_64
    cp lib/.libs/libraw_r.a libraw_r.a.x86_64
    

4. Create the Universal Binaries

Combine arm64 and x86_64 libraries:

    lipo -create libraw.a.x86_64 libraw.a.arm64 -output libraw.a
    lipo -create libraw_r.a.x86_64 libraw_r.a.arm64 -output libraw_r.a
    

Done. Result libraw.a and libraw_r.a are now Universal Binaries (x86_64 + arm64).

Windows: Building under Cygwin

Building and installation are completely similar to building and installation under Unix systems.

Windows: Native Building

Building under Windows has three steps:

You may need to edit Makefile.msvc to provide libjpeg/zlib paths to INCLUDE/LIB.

If all paths are set correctly and the include-files/libraries have been found, then the following will be compiled:

Only the thread-safe library is built under Win32, but it can be used with non-threaded applications as well. All examples are linked with the dynamic library (DLL); if static linking is necessary, one should link applications with library libraw_static.lib and set the preprocessor option /DLIBRAW_NODLL during compilation.

Windows-version compiles without LCMS support for now.

During building of DLL, all public functions are exported; further, the exported subset may be reduced.

Unfortunately, paths to include/ libraries depend on the way Visual C (or other compiler) is installed; therefore, it is impossible to specify some standard paths in Makefile.msvc.

Windows Installation

No installation under Windows is supported. It is assumed that all DLLs will be supplied together with the software using them (and this software will perform the installation). Accordingly, in building of programs using LibRaw, the paths to libraries, DLLs, and include-files should be specified manually.

[back to Index]