1. Michael Granger
  2. ruby-pg
  3. Issues


Issue #71 resolved

Mingw Compilation Broken

Anonymous created an issue

Version 0.11 no longer compiles on Windows using mingw32 + mysy. Trace back is below. The issue is that the linking line is not including the correct libraries. It is possible to work around by doing this:


$ gem update pg --platform=ruby

Fix is easy, in the extconf.rb file check for CROSS_COMPILING or mingw or mswin.



{{{ $ gem update pg --platform=ruby Updating installed gems Updating pg Fetching: pg-0.11.0.gem (100%) Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension.

    c:/MinGW/local/ruby/bin/ruby.exe extconf.rb

checking for pg_config... yes Using config values from c:\MinGW\local\bin/pg_config.exe checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for PQconnectdb() in -lpq... yes checking for PQconnectionUsedPassword()... yes checking for PQisthreadsafe()... yes checking for PQprepare()... yes checking for PQexecParams()... yes checking for PQescapeString()... yes checking for PQescapeStringConn()... yes checking for PQgetCancel()... yes checking for lo_create()... yes checking for pg_encoding_to_char()... yes checking for PQsetClientEncoding()... yes checking for struct pgNotify.extra in libpq-fe.h... yes checking for unistd.h... yes creating extconf.h creating Makefile

make gcc -I. -I. -Ic:/MinGW/local/ruby/lib/ruby/1.8/i386-mingw32 -I. -DRUBY_EXTCONF_H=\"extconf.h\" -Ic:/MinGW/local/include -g -O2 -c compat.c gcc -I. -I. -Ic:/MinGW/local/ruby/lib/ruby/1.8/i386-mingw32 -I. -DRUBY_EXTCONF_H=\"extconf.h\" -Ic:/MinGW/local/include -g -O2 -c pg.c gcc -shared -s -o pg_ext.so compat.o pg.o -L. -Lc:/MinGW/local/ruby/lib -L. -Lc:/MinGW/local/lib -Wl,--enable-auto-image-base,--enable-auto-import,--export-all -lmsvcrt-ruby18 -lpq -lshell32 -lwsock32 pg.o: In function create_crt_fd': c:/MinGW/local/ruby/lib/ruby/gems/1.8/gems/pg-0.11.0/ext/pg.c:2031: undefined reference toWSADuplicateSocketA@12' c:/MinGW/local/ruby/lib/ruby/gems/1.8/gems/pg-0.11.0/ext/pg.c:2032: undefined reference to `WSASocketA@24' collect2: ld returned 1 exit status make: *** [pg_ext.so] Error 1

Gem files will remain installed in c:/MinGW/local/ruby/lib/ruby/gems/1.8/gems/pg-0.11.0 for inspection. Results logged to c:/MinGW/local/ruby/lib/ruby/gems/1.8/gems/pg-0.11.0/ext/gem_make.out Nothing to update }}}

Comments (3)

  1. Michael Granger repo owner
    • changed status to open

    The 'CROSS_COMPILING' ENV var is for extconf.rb, for the binary Windows gem builds, so extconf already checks it. I suspect what's causing your compile to succeed is the line:

    have_library( 'ws2_32', 'WSASocket') && append_library( $libs, 'ws2_32' )

    which is inside that conditional. I don't know enough about about Windows programming to know if more than just that library are required, but I'll try duplicating your issue and see if adding a check for RUBY_PLATFORM =~ /mswin|mingw/ will fix it.

  2. Log in to comment