Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinGW 下也跟 MSVC 一样导出所有符号,修复链接错误 #1664

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

driver1998
Copy link

@driver1998 driver1998 commented Apr 22, 2024

MSYS2 UCRT64 环境(GCC 13.2.0 + MinGW + Universal CRT)下测试通过。

Fixes #1600, #1575

@driver1998
Copy link
Author

GmSSL/tools/tlcp_client.c

Lines 251 to 281 in bdd2149

for (;;) {
fd_set fds;
FD_ZERO(&fds);
FD_SET(conn.sock, &fds);
if (read_stdin)
#ifdef WIN32
FD_SET(_fileno, &fds);
#else
FD_SET(STDIN_FILENO, &fds);
#endif
if (select(conn.sock + 1, &fds, NULL, NULL, NULL) < 0) {
fprintf(stderr, "%s: select error\n", prog);
goto end;
}
#ifdef WIN32
if (read_stdin && FD_ISSET(_fileno, &fds)) {
#else
if (read_stdin && FD_ISSET(STDIN_FILENO, &fds)) {
#endif
if (fgets(buf, sizeof(buf), stdin)) {
if (tls_send(&conn, (uint8_t *)buf, strlen(buf), &len) != 1) {
fprintf(stderr, "%s: send error\n", prog);
goto end;
}
} else {
if (!feof(stdin)) {
fprintf(stderr, "%s: length of input line exceeds buffer size\n", prog);
goto end;

此处的 _fileno 我找不到对应的变量定义,编译时似乎是指向了 Windows 的 _fileno 函数,于是触发了函数指针强转为 SOCKET (UINT_PTR) 的问题,这在 GCC 上是 warning,Clang 上是 error。

附 Clang 下的报错信息

FAILED: CMakeFiles/gmssl-bin.dir/tools/tlcp_client.c.obj
D:\msys64\clang64\bin\cc.exe -DENABLE_ASM_UNDERSCORE_PREFIX -DENABLE_SHA2 -D_WINSOCK_DEPRECATED_NO_WARNINGS -ID:/Projects/GmSSL/include  -MD -MT CMakeFiles/gmssl-bin.dir/tools/tlcp_client.c.obj -MF CMakeFiles\gmssl-bin.dir\tools\tlcp_client.c.obj.d -o CMakeFiles/gmssl-bin.dir/tools/tlcp_client.c.obj -c D:/Projects/GmSSL/tools/tlcp_client.c
D:/Projects/GmSSL/tools/tlcp_client.c:258:4: warning: comparison between pointer and integer ('SOCKET' (aka 'unsigned long long') and 'int (*)(FILE *) __attribute__((cdecl))' (aka 'int (*)(struct _iobuf *)')) [-Wpointer-integer-compare]
  258 |                         FD_SET(_fileno, &fds);
      |                         ^~~~~~~~~~~~~~~~~~~~~
D:/msys64/clang64/include/psdk_inc/_fd_types.h:77:40: note: expanded from macro 'FD_SET'
   77 |                 if (((fd_set *)(set))->fd_array[__i] == (fd)) {         \
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~
D:/Projects/GmSSL/tools/tlcp_client.c:258:4: error: incompatible pointer to integer conversion assigning to 'SOCKET' (aka 'unsigned long long') from 'int (FILE *) __attribute__((cdecl))' (aka 'int (struct _iobuf *)') [-Wint-conversion]
  258 |                         FD_SET(_fileno, &fds);
      |                         ^~~~~~~~~~~~~~~~~~~~~
D:/msys64/clang64/include/psdk_inc/_fd_types.h:83:37: note: expanded from macro 'FD_SET'
   83 |                         ((fd_set *)(set))->fd_array[__i] = (fd);        \
      |                                                          ^ ~~~~
1 warning and 1 error generated.
ninja: build stopped: subcommand failed.

请问这真的符合意图吗?目前我不敢动,测试好像也没测到这一块。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

请教:用mingw怎么编译?
1 participant