安装dm-postgres-adapter gem时出错(找不到PostgreSQL构建环境)

时间:2015-10-13 08:32:43

标签: ruby-on-rails ruby postgresql rubygems datamapper

我需要在Windows 7(64位)上使用sinatra和datamapper在Postgres上实现一个小的ruby webapp。为了开始,我通过Rubyinstaller.org安装了Ruby 2.1.7(x64)和DevKit DevKit mingw64-64-4.7.2,并通过官方站点安装了postgresql-9.4.4-3-windows-x64。在this Datamapper guide之后,我首先尝试安装dm-postgres-adapter。

这就是我得到的:

C:\Ruby DevKit>gem install dm-postgres-adapter
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing dm-postgres-adapter:
        ERROR: Failed to build gem native extension.

    C:/Ruby21-x64/bin/ruby.exe extconf.rb
checking for main() in -lpq... no
checking for main() in -llibpq... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby21-x64/bin/ruby
        --with-pgsql-server-dir
        --without-pgsql-server-dir
        --with-pgsql-server-include
        --without-pgsql-server-include=${pgsql-server-dir}/include
        --with-pgsql-server-lib
        --without-pgsql-server-lib=${pgsql-server-dir}/lib
        --with-pgsql-client-dir
        --without-pgsql-client-dir
        --with-pgsql-client-include
        --without-pgsql-client-include=${pgsql-client-dir}/include
        --with-pgsql-client-lib
        --without-pgsql-client-lib=${pgsql-client-dir}/lib
        --with-pgsql-win32-dir
        --without-pgsql-win32-dir
        --with-pgsql-win32-include
        --without-pgsql-win32-include=${pgsql-win32-dir}/include
        --with-pgsql-win32-lib
        --without-pgsql-win32-lib=${pgsql-win32-dir}/lib
        --with-pqlib
        --without-pqlib
        --with-libpqlib
        --without-libpqlib
Could not find PostgreSQL build environment (libraries & headers): Makefile not
created

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/do_pos
tgres-0.10.16 for inspection.
Results logged to C:/Ruby21-x64/lib/ruby/gems/2.1.0/extensions/x64-mingw32/2.1.0
/do_postgres-0.10.16/gem_make.out

C:\ Ruby21-x64 \ lib \ ruby​​ \ gems \ 2.1.0 \ extensions \ x64-mingw32 \ 2.1.0 \ do_postgres-0.10.16 \ mkmf.log的内容是:

have_library: checking for main() in -lpq... -------------------- no

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby21-x64/include/ruby-2.1.0/x64-mingw32 -IC:/Ruby21-x64/include/ruby-2.1.0/ruby/backward -IC:/Ruby21-x64/include/ruby-2.1.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -UENABLE_NLS -DHAVE_GETTIMEOFDAY -DHAVE_CRYPT -DHAVE_NO_DATETIME_NEWBANG conftest.c  -L. -LC:/Ruby21-x64/lib -L.      -lx64-msvcrt-ruby210  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return 0;
8: }
/* end */

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby21-x64/include/ruby-2.1.0/x64-mingw32 -IC:/Ruby21-x64/include/ruby-2.1.0/ruby/backward -IC:/Ruby21-x64/include/ruby-2.1.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -UENABLE_NLS -DHAVE_GETTIMEOFDAY -DHAVE_CRYPT -DHAVE_NO_DATETIME_NEWBANG conftest.c  -L. -LC:/Ruby21-x64/lib -L.      -lx64-msvcrt-ruby210 -lpq  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
conftest.c: In function 't':
conftest.c:16:32: warning: variable 'p' set but not used [-Wunused-but-set-variable]
c:/ruby devkit/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lpq
collect2.exe: error: ld returned 1 exit status
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
16: int t(void) { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
/* end */

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby21-x64/include/ruby-2.1.0/x64-mingw32 -IC:/Ruby21-x64/include/ruby-2.1.0/ruby/backward -IC:/Ruby21-x64/include/ruby-2.1.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -UENABLE_NLS -DHAVE_GETTIMEOFDAY -DHAVE_CRYPT -DHAVE_NO_DATETIME_NEWBANG conftest.c  -L. -LC:/Ruby21-x64/lib -L.      -lx64-msvcrt-ruby210 -lpq  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
conftest.c: In function 't':
conftest.c:16:1: error: too few arguments to function 'main'
conftest.c:8:5: note: declared here
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
16: int t(void) { main(); return 0; }
/* end */

--------------------

have_library: checking for main() in -llibpq... -------------------- no

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby21-x64/include/ruby-2.1.0/x64-mingw32 -IC:/Ruby21-x64/include/ruby-2.1.0/ruby/backward -IC:/Ruby21-x64/include/ruby-2.1.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -UENABLE_NLS -DHAVE_GETTIMEOFDAY -DHAVE_CRYPT -DHAVE_NO_DATETIME_NEWBANG conftest.c  -L. -LC:/Ruby21-x64/lib -L.      -lx64-msvcrt-ruby210 -llibpq  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
conftest.c: In function 't':
conftest.c:16:32: warning: variable 'p' set but not used [-Wunused-but-set-variable]
c:/ruby devkit/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llibpq
collect2.exe: error: ld returned 1 exit status
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
16: int t(void) { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
/* end */

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby21-x64/include/ruby-2.1.0/x64-mingw32 -IC:/Ruby21-x64/include/ruby-2.1.0/ruby/backward -IC:/Ruby21-x64/include/ruby-2.1.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -UENABLE_NLS -DHAVE_GETTIMEOFDAY -DHAVE_CRYPT -DHAVE_NO_DATETIME_NEWBANG conftest.c  -L. -LC:/Ruby21-x64/lib -L.      -lx64-msvcrt-ruby210 -llibpq  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
conftest.c: In function 't':
conftest.c:16:1: error: too few arguments to function 'main'
conftest.c:8:5: note: declared here
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
16: int t(void) { main(); return 0; }
/* end */

--------------------

正如错误消息所指出的那样,我试图使用几个配置选项来尝试指定PostgreSQL安装路径,即

gem install -p dm-postgres-adapter -- --with-pgsql-server-dir=C:/Program Files/PostgreSQL/9.4    
gem install -p dm-postgres-adapter -- --with-pgsql-server-include=C:/Program Files/PostgreSQL/9.4/include
gem install -p dm-postgres-adapter -- --with-pgsql-win32-dir=C:/Program Files/PostgreSQL/9.4

但没有改变结果。经过一些研究后我发现在Linux上这个问题通常是通过RPM安装一些postgres-dev软件包来解决的。但是在Windows上该怎么办?

任何帮助将不胜感激!谢谢!

1 个答案:

答案 0 :(得分:0)

嗯,我希望这是一个答案: 在阅读了有关Windows 64位系统下的gem / devkit问题之后,我决定下载/安装32位(x86)的所有内容(postgres,rubyinstaller,devkit)。 dm-postgres-adapter,data_mapper和所有依赖项顺利安装。