MinGW-w64 (x86_64-pc-msys) である MinGW で Botan をビルドしようとしています。以下に示すように、MinGWで失敗しています。私はそれをMCVEに減らしたと思います:
#include <sys/select.h>
#include <winsock2.h>
#include <windows.h>
#include <memory>
int main(int argc, char* argv[])
{
fd_set fds;
FD_ZERO(&fds);
FD_SET(0, &fds);
timeval tv;
tv.tv_sec = 5;
tv.tv_usec = 0;
int rc = select(1, &fds, NULL, NULL, &tv);
return 0;
}
結果は次のとおりです。
$ g++ -m64 -pthread -std=c++11 test.cxx -o test.exe
In file included from /usr/include/w32api/winsock2.h:56:0,
from test.cxx:2:
/usr/include/w32api/psdk_inc/_fd_types.h:100:2: warning: #warning "fd_set and associated macros have been defined in sys/types. This can cause runtime problems with W32 sockets" [-Wcpp]
#warning "fd_set and associated macros have been defined in sys/types. \
^~~~~~~
In file included from test.cxx:2:0:
/usr/include/w32api/winsock2.h:995:34: error: conflicting declaration of C function ‘int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, PTIMEVAL)’
WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL timeout);
^~~~~~
In file included from test.cxx:1:0:
/usr/include/sys/select.h:73:5: note: previous declaration ‘int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, timeval*)’
int select __P ((int __n, fd_set *__readfds, fd_set *__writefds,
^~~~~~
最初に含める<sys/select.h>
ことが重要です。Windows ヘッダーの後にインクルードしても、問題は発生しません。含める<memory>
ことが重要です。には、既に含まれている<memory>
のような追加のヘッダーが含まれています。<sys/select.h>
私が知る限り、MinGW ヘッダーが問題を引き起こしています。これらは、2 つの異なる署名で同じ機能を提供します。
/usr/include/w32api/winsock2.h
:
int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, PTIMEVAL)
/usr/include/sys/select.h
int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, timeval*)
問題は最後の引数のようです。ある場合はそうでPTIMEVAL
あり、他の場合はそうですtimeval*
。これはメーリング リストに関連しているようですが、何をすべきかわかりません: struct timeval の使用法を PTIMEVAL に置き換え、 LP64 で TIMEVAL を別の方法で定義します。
What do I have to look out for when applications to porting applications to 64 bit Cygwin?で詳しく説明されているように、ポインター サイズの問題がいくつかある可能性があります。ですが、これは MinGW コードです (Botan コードではありません)。
問題は何ですか?どうすれば修正できますか?
こちらはぼたんさんsrc/lib/utils/socket/socket.cpp
。
コンパイルエラーは次のとおりです。
g++ -fstack-protector -m64 -pthread -std=c++11 -D_REENTRANT -O3 -momit-leaf-frame-pointer \
-Wall -Wextra -Wpedantic -Wstrict-aliasing -Wcast-align -Wmissing-declarations \
-Wpointer-arith -Wcast-qual -Wzero-as-null-pointer-constant -Wnon-virtual-dtor \
-Ibuild/include -c src/lib/utils/socket/socket.cpp -o build/obj/lib/utils_socket.o
In file included from /usr/include/w32api/winsock2.h:56:0,
from src/lib/utils/socket/socket.cpp:35:
/usr/include/w32api/psdk_inc/_fd_types.h:100:2: warning: #warning "fd_set and associated macros have been defined in sys/types. This can cause runtime problems with W32 sockets" [-Wcpp]
#warning "fd_set and associated macros have been defined in sys/types. \
^~~~~~~
In file included from src/lib/utils/socket/socket.cpp:35:0:
/usr/include/w32api/winsock2.h:995:34: error: conflicting declaration of C function ‘int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, PTIMEVAL)’
WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL timeout);
^~~~~~
In file included from /usr/include/sys/types.h:68:0,
from /usr/include/pthread.h:11,
from /usr/lib/gcc/x86_64-pc-msys/6.3.0/include/c++/x86_64-pc-msys/bits/gthr-default.h:35,
from /usr/lib/gcc/x86_64-pc-msys/6.3.0/include/c++/x86_64-pc-msys/bits/gthr.h:148,
from /usr/lib/gcc/x86_64-pc-msys/6.3.0/include/c++/ext/atomicity.h:35,
from /usr/lib/gcc/x86_64-pc-msys/6.3.0/include/c++/memory:73,
from build/include/botan/types.h:17,
from build/include/botan/internal/socket.h:11,
from src/lib/utils/socket/socket.cpp:8:
/usr/include/sys/select.h:73:5: note: previous declaration ‘int select(int, _types_fd_set*, _types_fd_set*, _types_fd_set*, timeval*)’
int select __P ((int __n, fd_set *__readfds, fd_set *__writefds,
^~~~~~
make: *** [Makefile:1066: build/obj/lib/utils_socket.o] Error 1