Thread: GUC variables invisible to contrib/ modules under Win32
Hi everyone, I've been experimenting with compiling PostGIS (a contrib module) under Win32 and I've noticed a difference in accessing GUC variables between Linux and Win32 using PostgreSQL 8.0 beta 1. In part of the PostGIS statistics routines we have a check like this: #include "commands/vacuum.h" ... /* If the attstattarget column is negative, use the default value */ /* NB: it is okay to scribble on stats->attr since it's a copy */ if (attr->attstattarget < 0) attr->attstattarget = default_statistics_target; Under Linux, PostGIS compiles and links fine without any trouble. However, when compiling under Win32 we get the following message: Info: resolving _default_statistics_target by linking to __imp__default_statistics_target (auto-import) fu000024.o(.idata$3+0xc): undefined reference to `libpostgres_a_iname' nmth000023.o(.idata$4+0x0): undefined reference to `_nm__default_statistics_target' c:\mingw\bin\dllwrap.exe: c:\mingw\bin\gcc exited with status 1 The current "fix" to enable this to work correctly is to change the relevant line in /src/include/commands/vacuum.h from "extern int default_statistics_target;" to "extern DLLIMPORT int default_statistics_target;". However, I'm not convinced this is the correct fix given that other contrib modules may require access to other GUC variables. I've looked at guc.c and found GetConfigOption() which I think may be a better option since I don't think accessing the variable directly will work when using custom variables. Would this be the "correct" way to access GUC variable values from within other modules that would work correctly under both Win32 and UNIX-type OSs? Cheers, Mark. --- Mark Cave-Ayland Webbased Ltd. Tamar Science Park Derriford Plymouth PL6 8BX England Tel: +44 (0)1752 764445 Fax: +44 (0)1752 764446 This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person.
Mark Cave-Ayland wrote: > Under Linux, PostGIS compiles and links fine without any trouble. > However, when compiling under Win32 we get the following message: > > Info: resolving _default_statistics_target by linking to > __imp__default_statistics_target (auto-import) > fu000024.o(.idata$3+0xc): undefined reference to `libpostgres_a_iname' > nmth000023.o(.idata$4+0x0): undefined reference to > `_nm__default_statistics_target' > c:\mingw\bin\dllwrap.exe: c:\mingw\bin\gcc exited with status 1 > > > The current "fix" to enable this to work correctly is to change the > relevant line in /src/include/commands/vacuum.h from "extern int > default_statistics_target;" to "extern DLLIMPORT int > default_statistics_target;". However, I'm not convinced this is the > correct fix given that other contrib modules may require access to other > GUC variables. It would be fine if all non-static variables would be defined extern DLLIMPORT, but since non-backend modules don't regularly access those variables most won't have that keyword. Additionally, this is yet another M$ issue, non-existent anywhere else. A work around is to redefine the prototype when you use it, i.e. after all pgsql includes you define extern DLLIMPORT int default_statistics_target; in your sources. Apparently, the compiler will respect the latest definition and resolve the reference cleanly. Regards, Andreas