From bfebd30f81430bdc13871986ea1cbeb6ecb7c13a Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Sat, 20 May 2023 22:03:35 -0700 Subject: [PATCH] This PR fixes compiling the pg extension with MSVC 2022 when using extconf.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. --- ext/extconf.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/extconf.rb b/ext/extconf.rb index 9bf1c2e5f..d9b7b38bb 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -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}"