| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
| <html> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html; charset=windows-1252"> | |
| <title>LibRaw Compilation and Installation</title> | |
| </head> | |
| <body> <a href="index.html">[back to Index]</a> | |
| <h1>LibRaw Compilation and Installation</h1> | |
| <p>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).</p> | |
| <a name="unix"></a> | |
| <h2>Unix Systems (FreeBSD, Linux, Mac OS X)</h2> | |
| <p> To build the library, you will need a working C++ compiler (gcc 3+ and | |
| clang 2+ are OK) and the make utility. </p> | |
| <p>Additional libraries (optional):</p> | |
| <ul> | |
| <li>zlib (used to decode deflated DNGs)</li> | |
| <li>libjpeg8 (used to decode lossy DNGs and several old Kodak cameras)</li> | |
| </ul> | |
| <p> 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. </p> | |
| <h3>Compilation of Library and Examples</h3> | |
| <p> Unpack the downloaded distribution package.</p> | |
| <pre> tar xzvf LibRaw-X.YY.tar.gz | |
| </pre> | |
| <p>For GitHub downloads (clones), perform ./configure script generation via</p> | |
| <pre> autoreconf --install</pre> | |
| <p>Go to LibRaw directory and run <b>./configure</b> and <b>make</b>: </p> | |
| <pre>cd LibRaw-X.YY | |
| ./configure # with optional args | |
| make | |
| </pre> | |
| <p>As a result, you will compile</p> | |
| <ul> | |
| <li>Library libraw.a in the lib/ folder</li> | |
| <li><a href="Samples-LibRaw.html">Examples</a> in the bin/ folder (source | |
| codes of examples are in the samples/ folder).</li> | |
| </ul> | |
| <p>In the current version, only static libraries are built:</p> | |
| <ul> | |
| <li>libraw.a: non-thread-safe version</li> | |
| <li>libraw_r.a: thread-safe</li> | |
| </ul> | |
| <h3>Build via provided Makefiles</h3> | |
| <p>Several makefiles provided to simplify basic build process:</p> | |
| <ul> | |
| <li>Makefile.dist - for macOS/Unix builds</li> | |
| <li>Makefile.mingw - for MinGW/similar gcc/clang on Windows</li> | |
| <li>Makefile.msvc - for Microsoft nmake/Visual studio</li> | |
| </ul> | |
| To build via provided Makefile: edit it to adjust compilation flag and use | |
| make/gmake/nmake -f Makefile | |
| <h3>Build time defines</h3> | |
| <p>File size/memory limits:</p> | |
| <ul> | |
| <li>LIBRAW_MAX_ALLOC_MB_DEFAULT - memory use for main RAW image in | |
| megabytes (default 2048MB)</li> | |
| <li>LIBRAW_MAX_PROFILE_SIZE_MB - embedded profile size limit (256MB)</li> | |
| <li>LIBRAW_MAX_NONDNG_RAW_FILE_SIZE - non-DNG file size limit (2GB)</li> | |
| <li>LIBRAW_MAX_CR3_RAW_FILE_SIZE -CR3 file size limit (2GB)</li> | |
| <li>LIBRAW_MAX_DNG_RAW_FILE_SIZE - DNG file size limit (2GB if compiled | |
| without Adobe DNG SDK, 4GB for Adobe-DNG-SDK build)</li> | |
| <li>LIBRAW_MAX_THUMBNAIL_MB -maximum thumbnail size (512MB)</li> | |
| </ul> | |
| Other build-time parameters (defines) | |
| <ul> | |
| <li>LIBRAW_OWN_SWAB - use own swab() implementation, default for | |
| Unix/Linux/Android</li> | |
| <li>LIBRAW_WIN32_CALLS - C-runtime used hasWin32 calls (default: on | |
| forVisual Studio/Intel compiler)</li> | |
| <li>LIBRAW_WIN32_DLLDEFS -build tools has __dllimport/export</li> | |
| <li>LIBRAW_WIN32_UNICODEPATHS -Unicode wchar_t paths supported</li> | |
| <li>LIBRAW_NO_IOSTREAMS_DATASTREAM - do not build iostreams-based LibRaw | |
| datastream</li> | |
| <li>LIBRAW_USE_AUTOPTR - use std::auto_ptr for iostreams based datastream</li> | |
| </ul> | |
| <h3>Build parameters</h3> | |
| <p> ./configure script have some non-standard parameters: </p> | |
| <dl> | |
| <dt> --enable-openmp<br> | |
| --disable-openmp </dt> | |
| <dd> Enable/disable OpenMP support if compiler supports it. OpenMP is | |
| enabled by default. </dd> | |
| <dt> --enable-lcms<br> | |
| --disable-lcms </dt> | |
| <dd> 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 </dd> | |
| <dt> --enable-examples<br> | |
| --disable-examples </dt> | |
| <dd> Enables/disables examples compilation and installation. Enabled by | |
| default </dd> | |
| </dl> | |
| <h3>Installation and Usage</h3> | |
| <p>To install the library, run</p> | |
| <pre> sudo make install | |
| </pre> | |
| <p> It will place the libraries in <b>/usr/local/lib</b>, the include-files | |
| in <b>/usr/local/include</b> (subfolder of libraw) and LibRaw samples to | |
| <b>/usr/local/bin</b>. You can override installation path by using | |
| ./configure script. <br> | |
| To use LibRaw, add the following parameters to the compiler call (when | |
| building your own projects): </p> | |
| <ul> | |
| <li>Path to include-files: -I/usr/local/include</li> | |
| <li>Path to libraries: -L/usr/local/lib</li> | |
| <li>Library: -lraw (ordinary version) or -lraw_r (thread-safe version).</li> | |
| </ul> | |
| <h2>macOS: Building with OpenMP</h2> | |
| <p>On macOS, building with OpenMP requires libomp. The Homebrew libomp formula | |
| is installed as | |
| <a href="https://docs.brew.sh/FAQ#what-does-keg-only-mean">keg-only</a>, | |
| so:</p> | |
| <ul> | |
| <li>pkg-config will not find it;</li> | |
| <li>headers and libraries are not in standard system locations</li> | |
| </ul> | |
| <p>You must explicitly point the build to the libomp include and library paths | |
| using <b>brew --prefix</b>.</p> | |
| <h3>1. Install libomp:</h3> | |
| <pre> brew install libomp</pre> | |
| <h3>2. Configure environment and build:</h3> | |
| <pre> 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 | |
| </pre> | |
| <p>In the configure output, you should see a line similar to:</p> | |
| <pre> checking for OpenMP flag of C compiler... -Xpreprocessor -fopenmp</pre> | |
| <h3>3. Build:</h3> | |
| <pre> make -j10 | |
| </pre> | |
| <h2>macOS: Building Universal Binary with OpenMP</h2> | |
| <p>This section describes how to build a Universal Binary (arm64 + x86_64) | |
| with OpenMP.</p> | |
| <h3>1. Build and save the arm64 libraries</h3> | |
| <p>First build the project normally (as above) and store the resulting | |
| static libraries:</p> | |
| <pre> cp lib/.libs/libraw.a libraw.a.arm64 | |
| cp lib/.libs/libraw_r.a libraw_r.a.arm64 | |
| </pre> | |
| <h3>2. Install Intel Homebrew and libomp (x86_64)</h3> | |
| <p>You also need an x86_64 toolchain via Intel Homebrew.</p> | |
| <p>Install Intel Homebrew:</p> | |
| <pre> arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| </pre> | |
| <p>Ensure the Intel Homebrew prefix (<b>/usr/local</b>) is first in PATH for | |
| this terminal session so that any subsequent call to <b>brew</b> invokes | |
| specifically the Intel installation:</p> | |
| <pre> export PATH=/usr/local/bin:$PATH | |
| </pre> | |
| <p>Install libomp:</p> | |
| <pre> brew install libomp | |
| </pre> | |
| <p>Confirm that it's indeed the x86_64 version that's being found and | |
| reported by brew:</p> | |
| <pre> brew --prefix libomp | |
| </pre> | |
| <p>It should return <b>/usr/local/opt/libomp</b>.</p> | |
| <p>Note: The Intel Homebrew installation works correctly even when invoked | |
| from an Apple Silicon terminal.</p> | |
| <p>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 <b>clang++: error: unsupported option '-fopenmp'</b> when building sample apps, | |
| copy-paste the linker invocation from the make output and remove the trailing | |
| <b>-fopenmp</b> flag.</p> | |
| <h3>3. Configure and build the x86_64 libraries</h3> | |
| <p>Configure for x86_64 with OpenMP:</p> | |
| <pre> 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 | |
| </pre> | |
| <p>Check the configure output again to confirm OpenMP is detected.</p> | |
| <p>Note: these are the same configure options and compiler flags as before, | |
| but including <b>-arch x86_64</b> and of course it's the Intel version | |
| of Homebrew that's now substituting paths to libomp.</p> | |
| <p>Build:</p> | |
| <pre> make -j10 | |
| </pre> | |
| <p>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.</p> | |
| <p>Verify that the binary built is indeed Intel:</p> | |
| <pre> lipo -info lib/.libs/libraw.a | |
| </pre> | |
| <p>You should see:</p> | |
| <pre> Non-fat file: lib/.libs/libraw.a is architecture: x86_64 | |
| </pre> | |
| <p>Save the Intel build:</p> | |
| <pre> cp lib/.libs/libraw.a libraw.a.x86_64 | |
| cp lib/.libs/libraw_r.a libraw_r.a.x86_64 | |
| </pre> | |
| <h3>4. Create the Universal Binaries</h3> | |
| <p>Combine arm64 and x86_64 libraries:</p> | |
| <pre> 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 | |
| </pre> | |
| <p>Done. Result libraw.a and libraw_r.a are now Universal Binaries (x86_64 | |
| + arm64).<p> | |
| <h2>Windows: Building under Cygwin</h2> | |
| <p> Building and installation are completely similar to <a href="#unix">building | |
| and installation under Unix systems</a>. </p> | |
| <h2>Windows: Native Building</h2> | |
| <p> Building under Windows has three steps: </p> | |
| <ul> | |
| <li>Unpack the distribution package (if you have got no tar+gzip, take the | |
| LibRaw distribution package in the .ZIP format) and go to folder | |
| LibRaw-X.YYY. </li> | |
| <li>Set the environment parameters so that the compiler/linker would find | |
| the libraries and include-files. For Visual C++, this is done by running | |
| <b>vcvars32.bat</b>. </li> | |
| <li> Run<br> | |
| <b>nmake -f Makefile.msvc</b><br> | |
| </li> | |
| </ul> | |
| <p>You may need to edit Makefile.msvc to provide libjpeg/zlib paths to | |
| INCLUDE/LIB.</p> | |
| <p> If all paths are set correctly and the include-files/libraries have been | |
| found, then the following will be compiled:</p> | |
| <ul> | |
| <li>Library libraw_static.lib in folder lib</li> | |
| <li>Dynamic library bin/libraw.dll and linking library for it | |
| lib/libraw.lib</li> | |
| <li>Examples in folder bin/.</li> | |
| </ul> | |
| <p>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. </p> | |
| <p> Windows-version compiles without LCMS support for now. </p> | |
| <p> During building of DLL, all public functions are exported; further, the | |
| exported subset may be reduced. </p> | |
| <p> 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. </p> | |
| <h2>Windows Installation</h2> | |
| <p> 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. </p> | |
| <a href="index.html">[back to Index]</a> | |
| </body> | |
| </html> |