1

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
4

2 に答える 2

3

MinGW-w64 ( x86_64-pc-msys )である MinGW で Botan をビルドしようとしています。

これは間違ったターゲットであると思われます.MSYS2環境自体を意図せずに構築しています.MSYS2環境は確かにPOSIXyです. そのため、eg<sys/select.h>が引き込まれ、競合を引き起こしています。少なくとも、MSYS2 環境内でのみ使用するためにビルドする意図がある<winsock2.h>かどうか、または使用しようとしているとは思えません。<windows.h>MINGW64 用にビルドするように構成されているように、コマンドラインから MSYS を正しく呼び出したか、正しいショートカットを使用したことを確認するか、そうである場合は、MINGW64 用の gcc ツールチェーンを実際にインストールしたことを確認する必要があります。そうでない場合は、MINGW64 を適切に開いていてもMSYS2 の gcc ツールチェーンに静かにデフォルトで戻り、MSYS2 ビルドに固有のインクルードを取り込みます。MINGW64 の GCC は、次のコマンドを実行してインストール (または再インストール) できます。

pacman -Sy mingw-w64-x86_64-gcc

これを使用して、Windows 固有のヘッダーをインストールまたは再インストールすることもできます。

pacman -Sy mingw-w64-x86_64-headers-git 

これが完了したら、実行unameして正しいビルド環境にいることを確認します。

MINGW64_NT-10.0-18363

そしてgcc -dumpmachine、これは得られるはずです

x86_64-w64-mingw64

MSYS2 の場合、これらの値は次のようになります。

MSYS_NT-10.0-18363

x86_64-pc-msys

それぞれ。

なぜ私はこれを知っているのですか?文字通り、私は一晩中同じ問題で起きていました._WIN32と_WIN64が定義されていないこと、およびインクルードファイルが(/usr/includeではなく/mingw64/x86_64-w64-mingw32/include)から来ていることに気付いた後で、x86_64-pc用にビルドしていることに気付きました. x86_64-w64-mingw32 ではなく -msys。

(もちろん、上記のすべては、32 ビット Windows 用にビルドする場合にも当てはまります。MINGW32 環境を適切に呼び出したこと、および を実行したことを確認してくださいpacman -Sy mingw-w64-i686-gcc mingw-w64-i686-headers-git。 MSYS2 用に構成された gcc でビルドします。)

とにかく、この質問が2年前のものであることを考えると、OPはその後移動しました。しかし、これは簡単な設定ミスです。とにかく、これが役に立てば幸いです!私の間違いをしないでください !そして皆さんご安全に!

于 2020-04-28T14:34:14.637 に答える