Phusion white papers Phusion overview

Phusion Blog

Fixing Nginx PCRE compilation issues on OS X

By Hongli Lai on October 26th, 2012

A lot of people running OS X (including us!) have recently been suffering from problems with compiling Nginx. Compilation would fail with the error message that the symbol pcre_free_study is not found, within the context of the function pcre_free_studies in ngx_regex.o:

src/core/ngx_regex.o: In function `ngx_pcre_free_studies':
    src/core/ngx_regex.c:307: undefined reference to `pcre_free_study'
collect2: ld returned 1 exit status
make[1]: *** [objs/nginx] Error 1

What is pcre_free_study? A Google search revealed that it is related to recently added support for JIT compilation in the PCRE library, a regular expressions library used by Nginx.

Upon further inspection, it turns out that a recent OS X update installed /usr/lib/libpcre.0.dylib and /usr/include/pcre.h. OS X did not ship PCRE in the past and users had to manually install it with MacPorts or HomeBrew. However, the library that OS X now ships seems to be of a different version than the header file!

$ strings /usr/lib/libpcre.0.dylib | grep -F 8.
8.02 2010-03-19
$ less /usr/include/pcre.h
....
/* The current PCRE version information. */

#define PCRE_MAJOR          8
#define PCRE_MINOR          31
#define PCRE_PRERELEASE     
#define PCRE_DATE           2012-07-06

The compilation problem is caused by the fact that OS X did not ship a proper header file for PCRE. You can solve this problem by downloading the header file for PCRE 8.02 and copying it to /usr/include.