|
From: James S. <jam...@op...> - 2006-08-25 06:38:26
|
On Thu, 2006-08-24 at 23:20 -0700, Brian Dessent wrote: > James Steward wrote: > > > I've googled for this for a while now and I'm not sure what to do next. > > Try searching the mailing list archives first. This has come up before, > e.g. <http://sourceforge.net/mailarchive/message.php?msg_id=14887873>. > > > When I print the value of _WIN32_WINNT I get 0x400 so obviously the > > function isn't declared. That explains the implicit declarations > > warning. But what about the undefined references? The functions are in > > the library ws2_32.a. > > > > What do I need to do to resolve this? Is it a MinGW version or a > > Windows version that needs updating? Or something completely different? > > The problem, as I described before, is that getaddrinfo() only exists in > ws2_32 for Windows XP and higher. If you're willing to generate a > binary that only runs on XP (and fails with a "Cannot find procedure > entry point <whatever>" popup box on all other versions) then just do: > > #define WINVER WindowsXP > > ...before including any w32api headers. This signals that you want the > feature set of XP, and you don't care about older versions. Note that > WindowsXP is defined as 0x0501, and that _WIN32_WINNT gets set to WINVER > if not already defined, so this is the proper way of declaring this, not > "#define _WIN32_WINNT 0x0501". > > Now, to complicate things, Microsoft has added support for a > getaddrinfo() wrapper in their platform SDK, which works only for IPv4, > as a way of supporting such code on older versions of Windows. So if > you are using the platform SDK you can still call getaddrinfo() from > older versions, but you'll really be just calling the existing > underlying IPv4 function (gethostbyname() or whatever) and failing if > you try to use IPv6. > > So, as I said in that reply above, your options are essentially: > > 1. Live with XP-only binary. > 2. Write (and potentially contribute to the w32api project) a suitable > getaddrinfo() wrapper for older versions. > 3. If you're just using IPv4 then call the old standard IPv4 functions > directly (gethostby*). > > Note that the reason that you got a link error when you did not define > WINVER is because the getaddrinfo function (and most every Windows API > function) is declared as type WINAPI which is synonymous with the > stdcall calling convention, which dictates a function decoration of @nn > on the end. But if you call a function without a prototype (as happens > if you don't set WINVER high enough) then the compiler assumes the > default cdecl calling convention which does not have that decoration, > and thus you're trying to call an undecorated function, and the name > lookup fails at link time. Another very common way that this plays out > is that the function actually only exists as FooA and FooW for the ANSI > and UNICODE variants, but you're meant to call it as just Foo() and the > include header #defines it to the correct variant based on whether you > enabled a Unicode build. Here you get a similar link error if you call > a function that was not declared in a header. What a twisted tail...but thanks Brian. I'll see how I go from here. An XP only binary might be ok too. The target platform is XP Pro I believe. Cheers, James. P.S. Now I know why I put my hand down when the boss says write some program for Windows... |