我正在尝试使用自定义编译的postgres 8.4.7安装ruby pg gem。按预期工作:

sudo env ARCHFLAGS='-arch x86_64' gem install pg -- --with-pg-config=/path/to/my/pg_config

gem编译和安装正确,并在需要时加载正确的动态库。
但是,我想静态地链接gem,以便在多台机器上移植。我最合理的尝试:
sudo env ARCHFLAGS='-arch x86_64' gem install pg -- --with-pg-config=/path/to/my/pg_config --with-ldflags='-static'

失败,并显示以下错误消息:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-pg-config=/[edited]/pgsql-8.4.7/bin/pg_config --with-ldflags=-static
checking for /[edited]/pgsql-8.4.7/bin/pg_config... yes
MacOS X build: fixing architecture flags:
  using the value in ARCHFLAGS environment variable ("-arch x86_64").
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)

有什么建议吗?
谢谢!
更新:
从mkmf.log文件:

conftest.c: In function ‘t’:
conftest.c:5: error: too few arguments to function ‘PQconnectdb’
checked program was:
/* begin */
1: #include
2:
3: /*top*/
4: int main() { return 0; }
5: int t() { PQconnectdb(); return 0; }
/* end */

最佳答案

解决了的:
将Postgres静态库从[prefix]/lib dir复制到单独的位置,并在构建gem时显式传递新路径:

sudo env ARCHFLAGS='-arch x86_64' gem install pg -- --with-pg-config=/path/to/my/pg_config --with-pg-lib=/path/to/static/libs

细节:
mkmf.log文件中的关键信息有点过多:
"gcc -o conftest -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I.  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/[edited]/pgsql-9.0.3/include -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common   conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib -static -L/[edited]/pgsql-9.0.3/lib     -lruby -lpq  -lpthread -ldl  "
ld: library not found for -lcrt0.o
collect2: ld returned 1 exit status

将'-static'标志传递给链接器试图创建完全静态链接的二进制文件,但Mac OS X不支持此操作:
Static linking of user binaries on Mac OS X

关于ruby - 在10.6.7上针对libpq.a编译postgres ruby​​ gem,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5652158/

10-15 18:43