From 24ef127b6d1f268ca09f4c501b4655e914329c5a Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 28 Sep 2022 10:19:00 -0700 Subject: [PATCH] meson: mingw: Add -Wl,--disable-auto-import, enable when linking with readline I hadn't ported -Wl,--disable-auto-import over from the win32 template as I had focused on msvc for windows. The flag is desirable as it makes it easier to find problems one would have with msvc, particularly useful during cross compilation. This turned out to be a somewhat happy accident, as it allowed me to realize that readline actually works on windows these days, as long as auto imports to enable. Therefore enable auto-import again as part of linking to readline. We perhaps can come up with a better solution for the readline issue, but this seems good enough for now. Discussion: http://postgr.es/m/20220928022724.erzuk5v4ai4b53do@awork3.anarazel.de --- meson.build | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/meson.build b/meson.build index 0cd09ba430..c32cd792db 100644 --- a/meson.build +++ b/meson.build @@ -279,6 +279,8 @@ elif host_system == 'windows' ldflags += '-Wl,--stack,@0@'.format(cdata.get('WIN32_STACK_RLIMIT')) # Need to allow multiple definitions, we e.g. want to override getopt. ldflags += '-Wl,--allow-multiple-definition' + # Ensure we get MSVC-like linking behavior. + ldflags += '-Wl,--disable-auto-import' endif os_deps += cc.find_library('ws2_32', required: true) @@ -1080,6 +1082,13 @@ Use -Dreadline=false to disable readline support.'''.format(readline_dep)) readline = declare_dependency(dependencies: readline, include_directories: postgres_inc) endif + + # On windows with mingw readline requires auto-import to successfully + # link, as the headers don't use declspec(dllimport) + if host_system == 'windows' and cc.get_id() != 'msvc' + readline = declare_dependency(dependencies: readline, + link_args: '-Wl,--enable-auto-import') + endif endif # XXX: Figure out whether to implement mingw warning equivalent