libsndfile and pkg-config

From version 1.0.0 libsndfile has had the ability to read and write files of greater than 2 Gig in size on most OSes even if sizeof (long) == 4. OSes which support this feature include Linux (2.4 kernel, glibc6) on x86, PPC and probably others, Win32, MacOS X, *BSD, Solaris and probably others. OSes on 64 bit processors where the default compile environment is LP64 (longs and pointers are 64 bit ie Linux on DEC/Compaq/HP Alpha processors) automatically support large file access.

Other OSes including Linux on 32 bit processors, 32 bit Solaris and others require special compiler flags to add large file support. This applies to both the compilation of the library itself and the compilation of programs which link to the library.

Note : People using Win32, MacOS (both OS X and pre-OS X) or *BSD can disregard the rest of this document as it does not apply to either of these OSes.

The pkg-config program makes finding the correct compiler flag values and library location far easier. During the installation of libsndfile, a file named sndfile.pc is installed in the directory ${libdir}/pkgconfig (ie if libsndfile is installed in /usr/local/lib, sndfile.pc will be installed in /usr/local/lib/pkgconfig/).

In order for pkg-config to find sndfile.pc it may be necessary to point the environment variable PKG_CONFIG_PATH in the right direction.

        export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
	

Then, to compile a C file into an object file, the command would be:

        gcc `pkg-config --cflags sndfile` -c somefile.c
	

and to link a number of objects into an executable that links against libsndfile, the command would be:

        gcc `pkg-config --libs sndfile` obj1.o obj2.o -o program
	

Obviously all this can be rolled into a Makefile for easier maintenance.