我正在尝试使用自定义编译的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 */
答案 0 :(得分:1)
<强>解决强>:
将Postgres静态库复制到[prefix] / lib目录的单独位置,并在构建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不支持该文件: