Skip to content

Commit

Permalink
This PR fixes compiling the pg extension with MSVC 2022 when using ex…
Browse files Browse the repository at this point in the history
…tconf.rb, nmake and libpq installed by vcpkg (not mingw64).

Running the command:

ruby extconf.rb --with-pg-include=c:\Source\vcpkg\installed\x64-windows\include --with-pg-lib=c:\Source\vcpkg\installed\x64-windows\lib

Fails with linker errors:

pg_connection.obj : error LNK2019: unresolved external symbol __imp_WSAGetLastError referenced in function pg_rb_thread_io_wait

This is fixed by adding ws2_32.lib to the linker command.
  • Loading branch information
cfis committed May 21, 2023
1 parent 364e5f8 commit bfebd30
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
if dlldir && RbConfig::CONFIG["RPATHFLAG"].to_s.empty?
append_ldflags "-Wl,-rpath,#{dlldir.quote}"
end

if /mswin/ =~ RUBY_PLATFORM
$libs = append_library($libs, 'ws2_32')
end
end

$stderr.puts "Using libpq from #{dlldir}"
Expand Down

0 comments on commit bfebd30

Please sign in to comment.