After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 739656 - Function if_nametoindex can't be found by configure script when building with MinGW-w64 GCC 4.9.2
Function if_nametoindex can't be found by configure script when building with...
Status: RESOLVED DUPLICATE of bug 730352
Product: glib
Classification: Platform
Component: build
2.43.x
Other Windows
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-11-05 06:49 UTC by Wesley Chan
Modified: 2015-03-23 08:07 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Wesley Chan 2014-11-05 06:49:19 UTC
I'm trying to build GLib 2.43.0 with MinGW-w64 GCC 4.9.2 v3 r0.
The configure script tries to detect whether if_nametoindex() exists with this command

configure:23524: gcc -o conftest.exe -g -mms-bitfields conftest.c -lintl >&5

This is not gonna work even if I explicitly add that library to the end of the command line because conftest.c supposes that the function will be

char if_nametoindex ();

while the real one in netioapi.h is

NET_IFINDEX WINAPI if_nametoindex(
  PCSTR InterfaceName
);

Recently the MinGW-w64 group removed the version guard in netioapi.h so that the build breaks down. See here

http://sourceforge.net/p/mingw-w64/mingw-w64/ci/b2aa85ca326ca55a2965da168c3c2d1c508c5572/

Even if they don't change that file, after you finally decided to drop Windows XP, if_nametoindex() still cannot be detected too. So, please kindly add this to one of the TODOs. Thank you!
Comment 1 Wesley Chan 2014-11-05 07:06:45 UTC
"Recently the MinGW-w64 group removed the version guard in netioapi.h so that
the build breaks down."

Sorry. Here's some more details.

1. The configure script didn't find if_nametoindex(), so it decided to use its own one by NOT defining HAVE_IF_NAMETOINDEX in config.h.

2. gio/gsocket.c included config.h, and no HAVE_IF_NAMETOINDEX defined, so it declared its own one around line 1934.

3. At the same time, gio/gsocket.c included gnetworkingprivate.h in line 60, which included gnetworking.h in line 22, which included /MinGW/i686-w64-mingw32/include/iphlpapi.h in line 35, which included /MinGW/i686-w64-mingw32/include/netioapi.h in line 16, which declared another if_nametoindex() in line 319. This makes a conflict.
Comment 2 Wesley Chan 2014-11-06 09:06:43 UTC
A quick work around will be defining them manually after running the configure script like this.

sed -i "s/\/\* #undef HAVE_IF_INDEXTONAME \*\//#define HAVE_IF_INDEXTONAME 1/g" config.h
sed -i "s/\/\* #undef HAVE_IF_NAMETOINDEX \*\//#define HAVE_IF_NAMETOINDEX 1/g" config.h

Tested under Windows 7. It builds.
Comment 3 Dan Winship 2015-03-10 03:06:39 UTC
(In reply to Wesley Chan from comment #0)
> I'm trying to build GLib 2.43.0 with MinGW-w64 GCC 4.9.2 v3 r0.
> The configure script tries to detect whether if_nametoindex() exists with
> this command
> 
> configure:23524: gcc -o conftest.exe -g -mms-bitfields conftest.c -lintl >&5
> 
> This is not gonna work even if I explicitly add that library to the end of
> the command line

"that library"?

> because conftest.c supposes that the function will be
> 
> char if_nametoindex ();
> 
> while the real one in netioapi.h is
> 
> NET_IFINDEX WINAPI if_nametoindex(
>   PCSTR InterfaceName
> );

That actually doesn't matter. (It's a link-time test, and the linker doesn't know/care about the actual prototype, only whether *some* function with that name exists or not.)

Anyway, it sounds like the problem is just that we need to add something to LIBS before doing the test?

Or is this fixed in git master by bug 730352 anyway?
Comment 4 Fan, Chun-wei 2015-03-10 06:58:43 UTC
Hi,

Indeed, this should be fixed by 730352, as if if_nametoindex() can be found in the system's iphlpapi.dll, which is the case for Vista and later, the Windows implementation in gsocket.c would use the system's own if_nametoindex() in its iphlpapi.dll.

I am not so sure about MinGW-w64, but in order to have if_nametoindex() found during compilation and linking, one must define _WIN32_WINNT to 0x0600 (I did see the link you referred to, but I think it is better if you do so anyways) or higher before including the headers and link to iphlpapi.lib (that probably means -liphlpapi for you).  Perhaps the configure.ac script didn't do that when it checked for that function, note that configure.ac currently sets _WIN32_WINNT to 0x0501, which means XP.  Care to do a patch for this?

Hope this helps.

With blessings.
Comment 5 Wesley Chan 2015-03-23 08:07:17 UTC
This issue was solved as https://bugzilla.gnome.org/show_bug.cgi?id=730352#c22

*** This bug has been marked as a duplicate of bug 730352 ***