Both the cause of the problem and an easy solution became apparent when I ran bin/pg_config
at the command line.
pg_config
generates the variables that are used to control compilation and linking. Of particular interest are LIBDIR and LDFLAGS. LIBDIR specifies the location for static libraries, while LDFLAGS provides locations to search for dynamic libraries. On my system, LIBDIR was set correctly to /LibraryPostgreSQL/9.3/lib
, but LDFLAGS was set as follows:
LDFLAGS = -L../../../src/common -L/usr/local/lib -L/opt/local/20140109/lib -Wl,-dead-strip-dylibs
Since libpq.5.dylib
was not present at any of these locations, the gem failed to find it, and instead found an older version that happened to be installed at /usr/lib
.
One way to fix this would be to inject the correct file location into LDFLAGS, possibly by modifying the code in extconf.rb
that generates the config file. However, a much easier fix in this case is just to add a symlink in /usr/local/lib
to the correct file location:
/usr/local/lib> ln -s /Library/PostgreSQL/9.3/lib/libpq.5.dylib libpq.5.dylib
If you run into a similar issue, just examine the output of pg_config
, and see if you can place a symlink to the correct file location in one of the directories that is already specified by LDFLAGS.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…