Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#5432 closed defect (fixed)

GDAL fails to build on mingw32 with gcc 4.8.1

Reported by: rashadkm Owned by: warmerdam
Priority: high Milestone: 1.10.2
Component: default Version: 1.10.1
Severity: normal Keywords: compile, windows, mingw
Cc: gdal-dev

Description

compilation of GDAL 1.10.0 and 1.10.1 fails on Windows 7 with MinGW 32 bit for GCC 4.8.1

Error log:

gdalclientserver.cpp: In function 'GDALServerSpawnedProcess* GDALServerSpawnAsync()':
gdalclientserver.cpp:1531:69: error: 'getaddrinfo' was not declared in this scope
         nRet = getaddrinfo(osHost, pszColon + 1, &sHints, &psResults);
                                                                     ^
gdalclientserver.cpp:1557:31: error: 'freeaddrinfo' was not declared in this scope
         freeaddrinfo(psResults);
                               ^
make[1]: *** [gdalclientserver.lo] Error 1
make: *** [core-target] Error 2

Attachments (1)

mingw32-getaddrinfo.patch (763 bytes) - added by rashadkm 8 years ago.
mingw32 compilation patch for getaddrinfo

Download all attachments as: .zip

Change History (16)

comment:1 Changed 8 years ago by rashadkm

moving cpl_port.h after the #ifdef WIN32 ... seems to be the workaround for this issue. cpl_port.h check for win32 defines and includes cpl_config.h which check HAVE_GETADDRINFO. here this macro is undefined.

as a followup I got undefined reference to getaddrinfo in apps/gdalserver.c

gdalserver.c: In function 'CreateSocketAndBindAndListen':
gdalserver.c:127:5: warning: implicit declaration of function 'getaddrinfo' [-Wimplicit-function-declaration]
     nRet = getaddrinfo(NULL, pszService, &sHints, &psResults);
     ^
gdalserver.c:157:5: warning: implicit declaration of function 'freeaddrinfo' [-Wimplicit-function-declaration]
     freeaddrinfo(psResults);
     ^
.libs/gdalserver.o: In function `CreateSocketAndBindAndListen':
c:\sources\gdal-1.10.1\apps/gdalserver.c:127: undefined reference to `getaddrinfo'
c:\sources\gdal-1.10.1\apps/gdalserver.c:157: undefined reference to `freeaddrinfo'
c:\sources\gdal-1.10.1\apps/gdalserver.c:157: undefined reference to `freeaddrinfo'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [gdalserver.exe] Error 1
make: *** [apps-target] Error 2

comment:2 Changed 8 years ago by rashadkm

with the attached patch gdal was built sucessfully on windows MinGW GCC4.8.1

comment:3 Changed 8 years ago by rashadkm

Cc: gdal-dev added

comment:4 Changed 8 years ago by Even Rouault

Moving #include "cpl_port.h" afterwards will surely break all other targets, and especially MSVC compilation. I suppose the issue with the current code is that the mingw system headers used in the #ifdef WIN32 case have not getaddrinfo in them.

So could you revert your changes and test replacing

#ifndef HAVE_GETADDRINFO

by

#if defined(_MSC_VER) && !defined(HAVE_GETADDRINFO)

comment:5 Changed 8 years ago by rashadkm

I reverted the change reproduced the error. applied the new ifdef check as you said and it works..

However i am getting this warning which i think is ok to be ignored.

gdalserver.c: In function 'CreateSocketAndBindAndListen':
gdalserver.c:126:5: warning: implicit declaration of function 'getaddrinfo' [-Wi
mplicit-function-declaration]
     nRet = getaddrinfo(NULL, pszService, &sHints, &psResults);
     ^
gdalserver.c:156:5: warning: implicit declaration of function 'freeaddrinfo' [-W
implicit-function-declaration]
     freeaddrinfo(psResults);

Changed 8 years ago by rashadkm

Attachment: mingw32-getaddrinfo.patch added

mingw32 compilation patch for getaddrinfo

comment:6 Changed 8 years ago by Even Rouault

This is weird. How come do you get warnings about getaddrinfo and freeaddrinfo whereas they are protected in a #ifdef HAVE_GETADDRINFO section, that should not be defined any longer ? And do you confirm that you don't you anymore the linking errors : gdalserver.c:127: undefined reference to `getaddrinfo' ?

comment:7 Changed 8 years ago by rashadkm

Yes. I dont get any compilation problems or link errors. I will try make clean and run make again to to see if there is the same warning. Because I think these warnings show up somewhere after reverting changes in gcore/gdalclientserver.cpp, apps/gdalserver.c and applying the new patch. So when the first error comes in gcore i applied the #ifdef patch there and later on apps/gdalserver.c. I will cross check this tomorrow first thing in the morning

comment:8 Changed 8 years ago by rashadkm

Resolution: fixed
Status: newclosed

Yes. you are right. there was no warning and what i posted was from previous build. Gdal compilation seems fine with mingw gcc4.8.1 with msys make files. Marking this as fixed

comment:9 Changed 8 years ago by rashadkm

Resolution: fixed
Status: closedreopened

I had marked this bug as fixed as my compilation was sucessful. However patch is not integrated in source and hence reopening the bug

comment:10 Changed 8 years ago by Even Rouault

Just to be sure : with that patch, do you get any warning about missing getaddrinfo/freeaddrinfo functions ?

What is strange is that patch is not needed with older i586-mingw32-msvc from Ubuntu 10.04, nor with i686-pc-mingw32 from CentOS 6

comment:11 in reply to:  10 Changed 8 years ago by rashadkm

Replying to rouault:

Just to be sure : with that patch, do you get any warning about missing getaddrinfo/freeaddrinfo functions ?

No.

What is strange is that patch is not needed with older i586-mingw32-msvc from Ubuntu 10.04, nor with i686-pc-mingw32 from CentOS 6

I had tested on two windows 7 machine with latest mingw32. From mingw installer[1] I had selected msys, mingw, gcc,g++ 4.8.1. I had the same problem with gdal.1.10.0 also.

[1] http://www.mingw.org/download/installer?

comment:12 Changed 8 years ago by Even Rouault

I think the following alternate fix should do it :

trunk r27142 "Fix build on mingw32 with gcc 4.8.1 (#5432)"

comment:13 Changed 8 years ago by Even Rouault

Milestone: 1.10.2
Resolution: fixed
Status: reopenedclosed

ok, I've reproduced the error with a mingw install for windows host with gcc 4.8.1, and verified that the fix works.

branches/1.10 r27144 "Fix build on mingw32 with gcc 4.8.1 (#5432)"

comment:14 Changed 8 years ago by rashadkm

Is there a backport policy for this commit for gdal.1.10.1 atleast?

comment:15 Changed 8 years ago by Even Rouault

I don't understand your question. 1.10.1 has already been released, so I cannot change. The backport has been done on top of the 1.10 branch, so for a 1.10.2, if someone releases it one day. Anyway, it is also in the 1.11.0 that should be released soon.

Note: See TracTickets for help on using tickets.