nng
nng copied to clipboard
MinGW build problems
I ran into 3 problems building on MinGW:
- The 'mbed' libraries require libbcrypt and libws2_32 to link, at least when a static version of libmbedtls, et al, is used. Without those two libraries, the 'cmake' build of the makefiles fails when trying to determine the version of libmbedtls. My fix was
diff --git a/src/supplemental/tls/mbedtls/CMakeLists.txt b/src/supplemental/tls/mbedtls/CMakeLists.txt
index 27cf8927..016a0550 100644
--- a/src/supplemental/tls/mbedtls/CMakeLists.txt
+++ b/src/supplemental/tls/mbedtls/CMakeLists.txt
@@ -37,6 +37,6 @@ if (NNG_TLS_ENGINE STREQUAL "mbed")
else()
find_package(MbedTLS REQUIRED)
endif()
- nng_link_libraries_public(MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509)
+ nng_link_libraries_public(MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509 bcrypt ws2_32)
endif()
endif()
- Compile error for nng/src/platform/windows/win_tcpconn.c
nng/src/platform/windows/win_tcpconn.c:263:36: error: passing argument 1 of 'CancelIoEx' makes pointer from integer without a cast [-Wint-conversion]
263 | CancelIoEx(s, &c->send_io.olpd);
| ^
| |
| SOCKET {aka long long unsigned int}
In file included from C:/msys64-2024/ucrt64/include/winbase.h:21,
from C:/msys64-2024/ucrt64/include/windows.h:70,
from C:/Users/glenn/msys2/nng/src/platform/windows/win_impl.h:19,
from C:/Users/glenn/msys2/nng/src/core/platform.h:576,
from C:/Users/glenn/msys2/nng/src/core/nng_impl.h:27,
from C:/Users/glenn/msys2/nng/src/platform/windows/win_tcpconn.c:12:
C:/msys64-2024/ucrt64/include/ioapiset.h:27:48: note: expected 'HANDLE' {aka 'void *'} but argument is of type 'SOCKET' {aka 'long long unsigned int'}
27 | WINBASEAPI WINBOOL WINAPI CancelIoEx (HANDLE hFile, LPOVERLAPPED lpOverlapped);
| ~~~~~~~^~~~~
C:/Users/glenn/msys2/nng/src/platform/windows/win_tcpconn.c:264:36: error: passing argument 1 of 'CancelIoEx' makes pointer from integer without a cast [-Wint-conversion]
264 | CancelIoEx(s, &c->recv_io.olpd);
| ^
| |
| SOCKET {aka long long unsigned int}
C:/msys64-2024/ucrt64/include/ioapiset.h:27:48: note: expected 'HANDLE' {aka 'void *'} but argument is of type 'SOCKET' {aka 'long long unsigned int'}
27 | WINBASEAPI WINBOOL WINAPI CancelIoEx (HANDLE hFile, LPOVERLAPPED lpOverlapped);
| ~~~~~~~^~~~~
I'm not convinced that the CancelIoEx() function will work with a SOCKET argument. I don't see any mention of it in the MSDN doc for that function. There is a note on StackOverflow indicating that it works if WSA_FLAG_OVERLAPPED is used to create the socket.
My fix was simply to typecast to SOCKET
index 0e74ccfd..2532e431 100644
--- a/src/platform/windows/win_tcpconn.c
+++ b/src/platform/windows/win_tcpconn.c
@@ -260,8 +260,8 @@ tcp_close(void *arg)
c->s = INVALID_SOCKET;
if (s != INVALID_SOCKET) {
- CancelIoEx(s, &c->send_io.olpd);
- CancelIoEx(s, &c->recv_io.olpd);
+ CancelIoEx((HANDLE)s, &c->send_io.olpd);
+ CancelIoEx((HANDLE)s, &c->recv_io.olpd);
shutdown(s, SD_BOTH);
closesocket(s);
}
- For the final build, libbcrypt and libws2_32 are needed.
diff --git a/src/supplemental/tls/mbedtls/CMakeLists.txt b/src/supplemental/tls/mbedtls/CMakeLists.txt
index 27cf8927..016a0550 100644
--- a/src/supplemental/tls/mbedtls/CMakeLists.txt
+++ b/src/supplemental/tls/mbedtls/CMakeLists.txt
@@ -37,6 +37,6 @@ if (NNG_TLS_ENGINE STREQUAL "mbed")
else()
find_package(MbedTLS REQUIRED)
endif()
- nng_link_libraries_public(MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509)
+ nng_link_libraries_public(MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509 bcrypt ws2_32)
endif()
endif()
** Environment Details ** nng version: GitHub repo as of 3 Oct 2024 MSYS_NT-10.0-22631 3.4.10.x86_64 2023-12-22 10:06 UTC x86_64 Msys gcc.exe (Rev1, Built by MSYS2 project) 14.2.0 cmake version 3.28.1 mbedtls: GitHub repo as of 3 Oct 2024
Additional context build command: cmake -G Ninja -DNNG_ENABLE_TLS=ON -DNNG_TLS_ENGINE=mbed ..
I'm not sure without a lot more study of 'nng' of what the correct fixes would be. But I have a build now. And all the tests pass.