Opened 5 years ago

Closed 4 years ago

#11626 closed build error (fixed)

Don't use winsock.h with Cygwin 1.7

Reported by: wxWidgetSST Owned by:
Priority: high Milestone:
Component: build Version: stable-latest
Keywords: cygwin cygwin_1.7 select() Cc:
Blocked By: Blocking: #11629, #11629, #11629
Patch: no

Description

hello,

until recently, I had this combo in flawless use:

  • wxWidgets-2.8.10 / gcc-3.4.4 / cygwin-1.5.25 / WinXP-SP3

Now I made a new installation of cygwin 1.7.1 and switched to its gcc-4.3.4 package and cannot build wxWidget-2.8.10 anymore.

As I cannot find info about the combo

  • wxWidgets-2.8.10 / gcc-4.3.4 / cygwin-1.7.1 / WinXP-SP3

neither via google/gmane (wx mailing lists) nor on this track, I open this new ticket.
The newest cygwin gcc mentioned on
<http://wiki.wxwidgets.org/Supported_Platforms#Platforms_supported_by_wxMSW>
is cygwin g++ 3.4.4 .

All my variants of build attempts gave me consistently this error:

$ make BUILD=release SHARED=0
/var/tmp/wxWidgets-2.8.10/bk-deps g++ -c -o baselib_msw_utils.o -DWXMSW -I./src/tiff -I./src/jpeg -I./src/png -DwxUSE_GUI=0 -DwxUSE_BASE=1 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -I/var/tmp/wxWidgets-2.8.10/lib/wx/include/msw-ansi-release-static-2.8 -I./include -Wall -Wundef -Wno-ctor-dtor-privacy -O2 -fno-strict-aliasing ./src/msw/utils.cpp
In file included from ./src/msw/utils.cpp:56:
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../include/w32api/winsock.h:479: error: declaration of C function 'int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, const timeval*)' conflicts with
/usr/include/sys/select.h:31: error: previous declaration 'int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, timeval*)' here
./src/msw/utils.cpp: In function 'const wxChar* wxGetHomeDir(wxString*)':
./src/msw/utils.cpp:407: warning: 'int cygwin_conv_to_full_win32_path(const char*, char*)' is deprecated (declared at /usr/include/sys/cygwin.h:52)
./src/msw/utils.cpp:407: warning: 'int cygwin_conv_to_full_win32_path(const char*, char*)' is deprecated (declared at /usr/include/sys/cygwin.h:52)
make: * [baselib_msw_utils.o] Error 1

$

I even tried the command sequence named in INSTALL-MSW.txt (around ln.504) out of the wxWidget-2.8.10 package but this produces the very same error.


  • What are the odds that make the (my?) build system "w.gcc-4.x" see multiple definitions of function select in the context of src/msw/utils.cpp?

(one from <sys/select.h> and one from <winsock.h>) Whereas the build system "w.gcc-3.x" does no have this problem...

Attachments (1)

11626.txt download (1.7 KB) - added by austin987 5 years ago.
replace cygwin_conv_to_full_win32_path with cygwin_conv_path

Download all attachments as: .zip

Change History (20)

comment:1 Changed 5 years ago by wxWidgetSST

I added a line for gcc-4.3.4 to the wiki article "Supported Platforms", with reference to here.
<http://wiki.wxwidgets.org/Supported_Platforms#Platforms_supported_by_wxMSW>

comment:2 follow-up: Changed 5 years ago by vadz

  • Status changed from new to confirmed

Apparently you can't include <winsock.h> together with <sys/select.h>. The offending declarations in w32api.h are inside !__INSIDE_CYGWIN__ check but I don't know if we can just predefine this prior to including <winsock.h> to fix this problem or if this is going to result in even worse problems.

But maybe we actually don't need to include this header at all with Cygwin? After all, there is this comment in src/msw/utils.cpp:

// Doesn't work with Cygwin at present
#if wxUSE_SOCKETS && (defined(__GNUWIN32_OLD__) || defined(__WXWINCE__) || defined(__CYGWIN32__))
    // apparently we need to include winsock.h to get WSADATA and other stuff
    // used in wxGetFullHostName() with the old mingw32 versions
    #include <winsock.h>
#endif

but then the header is still included. Could you please test what happens if you just remove the test for __CYGWIN32__ from there?

comment:3 in reply to: ↑ 2 Changed 5 years ago by wxWidgetSST

Replying to vadz:

Could you please test what happens if you just remove the test for __CYGWIN32__ from there?

when I try following code

// Doesn't work with Cygwin at present
#if wxUSE_SOCKETS && (defined(__GNUWIN32_OLD__) || defined(__WXWINCE__))
    // apparently we need to include winsock.h to get WSADATA and other stuff
    // used in wxGetFullHostName() with the old mingw32 versions
    #include <winsock.h>
#endif

the very same build step barfs about many symbols "not been declared"/"not been declared in this scope" (e.g. 'WSADATA', 'wsa', 'gethostbyname_t' and many more)
well, exactly as the comment states.

comment:4 Changed 5 years ago by wxWidgetSST

another unfruitful hackish try:

// Doesn't work with Cygwin at present
#if wxUSE_SOCKETS && (defined(__GNUWIN32_OLD__) || defined(__WXWINCE__) || defined(__CYGWIN32__))
    // apparently we need to include winsock.h to get WSADATA and other stuff
    // used in wxGetFullHostName() with the old mingw32 versions

#if !(defined (__INSIDE_CYGWIN__))
#define __INSIDE_CYGWIN__
    #include <winsock.h>
#undef  __INSIDE_CYGWIN__
#endif /* 2010-01-13 SST - experimental __INSIDE_CYGWIN__ */

#endif

by forcing INSIDE_CYGWIN prior to include winsock.h, the thing about function select() appears to be satisfied, but the build stops with error

../src/msw/utils.cpp:218: error: invalid use of incomplete type 'struct hostent'
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../include/w32api/winsock.h:452: error: forward declaration of 'struct hosten

t'

then also including netdb.h makes thigs worse; additionally, "#include <winsock.h>" appears in additional 5 more files which I interpret as whatever kludge I'm trying to hack this way, needs to be deployed wider than justifiable - not the way to go.

comment:5 follow-up: Changed 5 years ago by neis

Well, if resolving the conflict between winsock.h and sys/select.h by not including winsock.h does not work, then maybe not including sys/select.h (for Cygwin) does work?
Also this conflict in header files seems like something that cygwin people might want to fix, so maybe it's worth reporting the compile error to them...

comment:6 in reply to: ↑ 5 ; follow-up: Changed 5 years ago by wxWidgetSST

Replying to neis:

Well, if resolving the conflict between winsock.h and sys/select.h by not including winsock.h does not work, then maybe not including sys/select.h (for Cygwin) does work?

thanks, you are following my thougts.
But I can't see sys/select.h being directly included in utils.cpp.

can you tell me by which way it slips in here?

a search gives me following files as candidates to fiddle with, which one to tackle, please?

$ pwd
/var/tmp/wxWidgets-2.8.10
$ grep -F 'sys/select.h' $(find . -type f )
./configure.in: AC_CHECK_HEADERS([sys/select.h], [AC_INCLUDES_DEFAULT()])
./include/wx/os2/app.h:#include <sys/select.h>
./configure:for ac_header in sys/select.h
./src/common/socketevtdispatch.cpp:# include <sys/select.h>
./src/os2/app.cpp:#include <sys/select.h>
./src/os2/app.cpp:#include <sys/select.h>
./src/gtk1/app.cpp: #include <sys/select.h>
./src/x11/evtloop.cpp:# include <sys/select.h>
./src/unix/utilsunx.cpp:# include <sys/select.h>
./src/unix/gsocket.cpp:# include <sys/select.h>
./src/unix/gsocket.cpp:#include <sys/select.h>
./src/unix/gsocket.cpp:#include <sys/select.h>
./src/unix/joystick.cpp:# include <sys/select.h>
./src/motif/evtloop.cpp:# include <sys/select.h>
./setup.h.in:/* Define if you have the <sys/select.h> header file. */
$

comment:7 in reply to: ↑ 6 Changed 5 years ago by neis

Neither configure[.in] nor other cpp files should at all be relevant while compiling, so sys/select.h is probably implicitly inluded by some other system header file (which would probably also explain, why the problem depends on the compiler version). The only way I know to find where it has been included from would be to look at the preprocessor output - searching for the first occurence of "sys/select.h" and then looking for the preceding header file name should work ...

comment:8 Changed 5 years ago by vadz

  • Keywords cygwin_1.7 added; cygwin_1.7.1 gcc-4.3.4 removed
  • Priority changed from blocker to high
  • Summary changed from Build problems using wxWidgets-2.8.10 / gcc-4.3.4 / cygwin-1.7.1 : multiple definitions of function select() to Don't use winsock.h with Cygwin 1.7
  • Version changed from 2.8.10 to 2.9-svn

As this reply on Cygwin mailing list indicate, we shouldn't include <winsock.h> when using Cygwin but this is not completely obvious as our code calls WSAStartup() and I am far from sure if we can really just avoid doing it with Cygwin. This would require some testing, at the very least.

For now I can only suggest building with wxUSE_SOCKETS==0.

BTW, a quick (if extremely dirty) way to find the location where a header is included is to temporarily remove it from your /usr/include. Then the compiler will give you an error message pinpointing the exact location of its inclusion.

comment:9 Changed 5 years ago by vadz

  • Blocking 11629 added

comment:10 follow-up: Changed 5 years ago by dward

Two new pieces of information:

(1) The same problem occurs with gcc 3.4.4 (in Cygwin 1.7.1).

(2) Renaming /usr/include/sys/select.h (to select.h-x) makes the problem go away. The file in question compiles without error. There is no complaint about select.h not being found.

Changed 5 years ago by austin987

replace cygwin_conv_to_full_win32_path with cygwin_conv_path

comment:11 follow-up: Changed 5 years ago by austin987

  • Patch set

I've attached a patch for this problem.

comment:12 Changed 5 years ago by austin987

Attached a patch for this problem.

comment:13 in reply to: ↑ 11 Changed 5 years ago by austin987

  • Patch unset

Replying to austin987:

I've attached a patch for this problem.

Please ignore, attached to wrong bug.

comment:14 in reply to: ↑ 10 Changed 5 years ago by rafuck

All sources will successfully compiled after two actions:
(1) remove /usr/include/sys/select.h (or rename it to select.h-x for example)
(2) change 103-th line in src/common/stopwatch.cpp
-#define wxGetTimeOfDay(tv, tz) gettimeofday(tv)
+#define wxGetTimeOfDay(tv, tz) gettimeofday((tv), NULL)

My system is WinXP with all updates. Cygwin version is 1.7.5
$gcc --version
gcc (GCC) 4.3.4 20090804 (release) 1
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

comment:15 Changed 5 years ago by vadz

Thanks for the workaround but this is not a real solution, we can't recommend people to rename or remove standard headers.

For wxGetTimeOfDay() it should normally already work in wx svn trunk as we do use 2 parameters unless WX_GETTIMEOFDAY_NO_TZ is defined.

comment:16 Changed 4 years ago by vadz

  • Keywords cygwin added

comment:17 Changed 4 years ago by vadz

  • Blocking

comment:18 Changed 4 years ago by vadz

  • Resolution set to fixed
  • Status changed from confirmed to closed

This should be fixed by r65057, please reopen if any problems persist or open new tickets for the new problems.

comment:19 Changed 4 years ago by vadz

  • Blocking

(In #11629) It seems like this one should be fixed too, at least I don't see any other problems here.

Note: See TracTickets for help on using tickets.