Coder Social home page Coder Social logo

Comments (50)

mrdeep1 avatar mrdeep1 commented on September 27, 2024 1

I don't have a good understanding of the source code of libcoap. Having to visit and update
every #ifdef WIN32 could be a huge challenge for me.

Fair comment. I do not have a suitable minGW environment at present to work on this to see what actually needs to be done, nor the time to get to it short term.

In the first instance, I would try just replacing _WIN32 with _WIN32_ignore in examples/coap-server.c and src/coap_io.c to see what other errors get thrown up.

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

The initial issue is that _WIN32 is getting defined by the minGW compiler, but the _WIN32 specific code is not currently set up for the conditional compilations when using minGW (which also defines __MINGW32__) instead of msvc.

It looks like every #ifdef _WIN32 may have to be visited and updated to handle __MINGW32__.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

I don't have a good understanding of the source code of libcoap. Having to visit and update every #ifdef WIN32 could be a huge challenge for me.

The initial issue is that _WIN32 is getting defined by the minGW compiler, but the _WIN32 specific code is not currently set up for the conditional compilations when using minGW (which also defines __MINGW32__) instead of msvc.

It looks like every #ifdef _WIN32 may have to be visited and updated to handle __MINGW32__.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

I don't have a good understanding of the source code of libcoap. Having to visit and update
every #ifdef WIN32 could be a huge challenge for me.

Fair comment. I do not have a suitable minGW environment at present to work on this to see what actually needs to be done, nor the time to get to it short term.

In the first instance, I would try just replacing _WIN32 with _WIN32_ignore in examples/coap-server.c and src/coap_io.c to see what other errors get thrown up.

Thank you for your help, and I look forward to your follow-up. I have already understood the power of libcoap, but I can't use it due to the reason of minGW. I am really unwilling to give up.

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

@MrHulu Can you please try out PR #1062 which compiles and runs the example coap-client and coap-server when there is no (D)TLS involved on a Windows 11 system.

I am getting link issues with OpenSSL and missing header files for GnuTLS which are all, I suspect, down to my lack of knowledge of the MSYS environment. Any feedback welcome.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

@MrHulu Can you please try out PR #1062 which compiles and runs the example coap-client and coap-server when there is no (D)TLS involved on a Windows 11 system.

I am getting link issues with OpenSSL and missing header files for GnuTLS which are all, I suspect, down to my lack of knowledge of the MSYS environment. Any feedback welcome.

I'm sorry, I have been out in the past few days and haven't had the opportunity to do any programming. I will try it later. Thank you! I'm so excited and can't wait to try PR #1062

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

@MrHulu Can you please try out PR #1062 which compiles and runs the example coap-client and coap-server when there is no (D)TLS involved on a Windows 11 system.

I am getting link issues with OpenSSL and missing header files for GnuTLS which are all, I suspect, down to my lack of knowledge of the MSYS environment. Any feedback welcome.

@mrdeep1 I cloned #1062, then opened VSCode, and started CMake. Everything was normal at the beginning.

[cmake] Not searching for unused variables given on the command line.
[cmake] -- compiling with client support
[cmake] -- compiling with server support
[cmake] -- compiling with OSCORE support
[cmake] -- compiling without epoll support
[cmake] -- PACKAGE VERSION..................4.3.1
[cmake] -- PACKAGE BUILD....................bsd-licensed-1732-g1b7b4b6
[cmake] -- ENABLE_DTLS:.....................FALSE
[cmake] -- ENABLE_TCP:......................TRUE
[cmake] -- ENABLE_CLIENT_MODE:..............TRUE
[cmake] -- ENABLE_SERVER_MODE:..............TRUE
[cmake] -- ENABLE_OSCORE:...................TRUE
[cmake] -- ENABLE_DOCS:.....................TRUE
[cmake] -- ENABLE_EXAMPLES:.................TRUE
[cmake] -- DTLS_BACKEND:....................default
[cmake] -- WITH_GNUTLS:.....................OFF
[cmake] -- WITH_TINYDTLS:...................OFF
[cmake] -- WITH_OPENSSL:....................OFF
[cmake] -- WITH_MBEDTLS:....................OFF
[cmake] -- HAVE_LIBTINYDTLS:................
[cmake] -- HAVE_LIBGNUTLS:..................
[cmake] -- HAVE_OPENSSL:....................
[cmake] -- HAVE_MBEDTLS:....................
[cmake] -- WITH_EPOLL:......................TRUE
[cmake] -- CMAKE_C_COMPILER:................D:/MinGW/bin/gcc.exe
[cmake] -- BUILD_SHARED_LIBS:...............FALSE
[cmake] -- CMAKE_BUILD_TYPE:................Release
[cmake] -- CMAKE_SYSTEM_PROCESSOR:..........AMD64
[cmake] -- WARNING_TO_ERROR:................FALSE
[cmake] -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
[cmake] CMake Warning at CMakeLists.txt:712 (message):
[cmake]   Doxygen need to be installed to generate the doxygen documentation
[cmake] 
[cmake] 
[cmake] -- Configuring done
[cmake] -- Generating done

Unfortunately, after running CMake and starting to compile, I encountered the same error as before.

[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_asn1.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_asn1.c:16:
[build] ../include/coap3/libcoap.h:33:17: note: previous declaration of 'ssize_t' was here
[build]    33 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] [6/35   5% :: 2.875] Building C object CMakeFiles/coap-3.dir/src/coap_address.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_address.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-g1b7b4b6\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_address.c.obj -MF CMakeFiles\coap-3.dir\src\coap_address.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_address.c.obj -c ../src/coap_address.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_address.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_address.c:16:
[build] ../include/coap3/libcoap.h:33:17: note: previous declaration of 'ssize_t' was here
[build]    33 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] ../src/coap_address.c: In function 'coap_resolve_address_info':
[build] ../src/coap_address.c:226:11: warning: implicit declaration of function 'getaddrinfo' [-Wimplicit-function-declaration]
[build]   226 |   error = getaddrinfo(addrstr, NULL, &hints, &res);
[build]       |           ^~~~~~~~~~~
[build] ../src/coap_address.c:366:3: warning: implicit declaration of function 'freeaddrinfo' [-Wimplicit-function-declaration]
[build]   366 |   freeaddrinfo(res);
[build]       |   ^~~~~~~~~~~~
[build] [6/35   8% :: 2.901] Building C object CMakeFiles/coap-3.dir/src/coap_encode.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_encode.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-g1b7b4b6\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_encode.c.obj -MF CMakeFiles\coap-3.dir\src\coap_encode.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_encode.c.obj -c ../src/coap_encode.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_encode.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_encode.c:16:
[build] ../include/coap3/libcoap.h:33:17: note: previous declaration of 'ssize_t' was here
[build]    33 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] [6/35  11% :: 2.985] Building C object CMakeFiles/coap-3.dir/src/coap_dtls.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_dtls.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-g1b7b4b6\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_dtls.c.obj -MF CMakeFiles\coap-3.dir\src\coap_dtls.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_dtls.c.obj -c ../src/coap_dtls.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_dtls.c:18:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_dtls.c:18:
[build] ../include/coap3/libcoap.h:33:17: note: previous declaration of 'ssize_t' was here
[build]    33 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] [6/35  14% :: 3.040] Building C object CMakeFiles/coap-3.dir/src/coap_debug.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_debug.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-g1b7b4b6\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_debug.c.obj -MF CMakeFiles\coap-3.dir\src\coap_debug.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_debug.c.obj -c ../src/coap_debug.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_debug.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_debug.c:16:
[build] ../include/coap3/libcoap.h:33:17: note: previous declaration of 'ssize_t' was here
[build]    33 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] ../src/coap_debug.c: In function 'coap_print_addr':
[build] ../src/coap_debug.c:251:7: warning: implicit declaration of function 'inet_ntop'; did you mean 'inet_ntoa'? [-Wimplicit-function-declaration]
[build]   251 |   if (inet_ntop(addr->addr.sa.sa_family, addrptr, (char *)p,
[build]       |       ^~~~~~~~~
[build]       |       inet_ntoa
[build] [6/35  17% :: 3.095] Building C object CMakeFiles/coap-3.dir/src/coap_async.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_async.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-g1b7b4b6\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_async.c.obj -MF CMakeFiles\coap-3.dir\src\coap_async.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_async.c.obj -c ../src/coap_async.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_async.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_async.c:16:
[build] ../include/coap3/libcoap.h:33:17: note: previous declaration of 'ssize_t' was here
[build]    33 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] ninja: build stopped: subcommand failed.

The good news is that there are fewer errors now compared to before, and your changes have been successful to a large extent. As for the OpenSSL linking issue you mentioned, I haven't encountered it yet. It could be that the OpenSSL error occurs after this point.

Do you need any further information from me, or is there anything else I can do to assist you? I will do my best to cooperate with you.

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

It would appear that your build environment has changed. For example coap_address.c.obj built originally but does not now due to the definition of ssize_t which was not changed in the patch.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

It would appear that your build environment has changed. For example coap_address.c.obj built originally but does not now due to the definition of ssize_t which was not changed in the patch.

The ssize_t type is defined in the <sys/types.h> header file, so this header file needs to be included before using ssize_t. However, the code is written on the Windows platform, which does not have this header file, even if MSYS is installed. In this case, you can use the SSIZE_T macro instead of ssize_t, which is an equivalent type on the Windows platform. The <BaseTsd.h> header file needs to be included to use the SSIZE_T macro.

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

SSIZE_T is not the underlying build issue here. To fix SSIZE_T, can you please try this change as I do not get that issue.

diff --git a/include/coap3/libcoap.h b/include/coap3/libcoap.h
index d7fcc13..5a2bdcd 100644
--- a/include/coap3/libcoap.h
+++ b/include/coap3/libcoap.h
@@ -30,8 +30,14 @@
 #pragma comment(lib,"Ws2_32.lib")
 #endif /* !defined(__MINGW32__) */
 #include <ws2tcpip.h>
+#ifndef _SSIZE_T_DECLARED
 typedef SSIZE_T ssize_t;
+#define        _SSIZE_T_DECLARED
+#endif
+#ifndef _IN_PORT_T_DECLARED
 typedef USHORT in_port_t;
+#define        _IN_PORT_T_DECLARED
+#endif
 #elif !defined (CONTIKI) && !defined (WITH_LWIP)
 #include <netinet/in.h>
 #include <sys/socket.h>

Depending on the MSYS environment, I am seeing different issues here. How you built the code as initially reported does not appear to be the same the second time round - which you referred to as using VSCode. Did you use VSCode the first time around?

When I installed MSYS, I was presented with 4 types of build environments. The UCRT64 version is what I did my testing against. What does uname on the command line report? Using the 4 different versions. I get different failures.

What I am running (in a command line script) is

cmake -E remove_directory build-test
cmake -E make_directory build-test
cd build-test
cmake .. -DENABLE_DTLS=OFF -DENABLE_DOCS=OFF
cmake --build .

Note: With 3 of the 4 MSYS build environments, I get the following warning (which seems to make no difference)

System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-22621 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

For the getaddrinfo etc. errors, I suspect that you do not have package msys2-w32api-headers installed.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

@mrdeep1 Sorry, I should have provided more information. I have two different MininGW compilers.
It was indeed my first compiler that had the problem, so I downloaded two compilers.Please ignore my last reply, I used the wrong compiler to build it.
I think my second compiler is fine, but it also reports an error that looks the same as the very first one.

The first MinGW

Second MinGW

  • Downloaded via: via msys2 to install
  • Name: GCC 12.2.0-w64-mingw32
  • Failed to build:
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_io.c.obj 
[build] D:\msys\mingw64\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-g1b7b4b6\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_io.c.obj -MF CMakeFiles\coap-3.dir\src\coap_io.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_io.c.obj -c ../src/coap_io.c
[build] ../src/coap_io.c: In function 'coap_socket_send':
[build] ../src/coap_io.c:744:14: warning: implicit declaration of function 'CMSG_SPACE'; did you mean 'C1_SPACE'? [-Wimplicit-function-declaration]
[build]   744 |     char buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
[build]       |              ^~~~~~~~~~
[build]       |              C1_SPACE
[build] ../src/coap_io.c:776:16: warning: implicit declaration of function 'CMSG_FIRSTHDR'; did you mean 'WSA_CMSG_FIRSTHDR'? [-Wimplicit-function-declaration]
[build]   776 |         cmsg = CMSG_FIRSTHDR(&mhdr);
[build]       |                ^~~~~~~~~~~~~
[build]       |                WSA_CMSG_FIRSTHDR
[build] ../src/coap_io.c:776:14: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]   776 |         cmsg = CMSG_FIRSTHDR(&mhdr);
[build]       |              ^
[build] ../src/coap_io.c:777:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   777 |         cmsg->cmsg_level = SOL_IP;
[build]       |             ^~
[build] ../src/coap_io.c:778:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   778 |         cmsg->cmsg_type = IP_PKTINFO;
[build]       |             ^~
[build] ../src/coap_io.c:779:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   779 |         cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
[build]       |             ^~
[build] ../src/coap_io.c:779:26: warning: implicit declaration of function 'CMSG_LEN' [-Wimplicit-function-declaration]
[build]   779 |         cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
[build]       |                          ^~~~~~~~
[build] ../src/coap_io.c:805:14: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]   805 |         cmsg = CMSG_FIRSTHDR(&mhdr);
[build]       |              ^
[build] ../src/coap_io.c:806:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   806 |         cmsg->cmsg_level = IPPROTO_IPV6;
[build]       |             ^~
[build] ../src/coap_io.c:807:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   807 |         cmsg->cmsg_type = IPV6_PKTINFO;
[build]       |             ^~
[build] ../src/coap_io.c:808:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   808 |         cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
[build]       |             ^~
[build] ../src/coap_io.c:828:12: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]   828 |       cmsg = CMSG_FIRSTHDR(&mhdr);
[build]       |            ^
[build] ../src/coap_io.c:829:11: error: invalid use of undefined type 'struct cmsghdr'
[build]   829 |       cmsg->cmsg_level = SOL_IP;
[build]       |           ^~
[build] ../src/coap_io.c:830:11: error: invalid use of undefined type 'struct cmsghdr'
[build]   830 |       cmsg->cmsg_type = IP_PKTINFO;
[build]       |           ^~
[build] ../src/coap_io.c:831:11: error: invalid use of undefined type 'struct cmsghdr'
[build]   831 |       cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
[build]       |           ^~
[build] ../src/coap_io.c:872:21: warning: implicit declaration of function 'sendmsg' [-Wimplicit-function-declaration]
[build]   872 |     bytes_written = sendmsg(sock->fd, &mhdr, 0);
[build]       |                     ^~~~~~~
[build] ../src/coap_io.c: In function 'coap_socket_recv':
[build] ../src/coap_io.c:974:9: error: invalid use of undefined type 'struct cmsghdr'
[build]   974 |     cmsg->cmsg_len = CMSG_LEN(sizeof(buf));
[build]       |         ^~
[build] ../src/coap_io.c:975:9: error: invalid use of undefined type 'struct cmsghdr'
[build]   975 |     cmsg->cmsg_level = -1;
[build]       |         ^~
[build] ../src/coap_io.c:976:9: error: invalid use of undefined type 'struct cmsghdr'
[build]   976 |     cmsg->cmsg_type = -1;
[build]       |         ^~
[build] ../src/coap_io.c:979:10: error: 'lpWSARecvMsg' undeclared (first use in this function)
[build]   979 |     if (!lpWSARecvMsg) {
[build]       |          ^~~~~~~~~~~~
[build] ../src/coap_io.c:979:10: note: each undeclared identifier is reported only once for each function it appears in
[build] ../src/coap_io.c:987:5: error: 'r' undeclared (first use in this function)
[build]   987 |     r = lpWSARecvMsg(sock->fd, &mhdr, &dwNumberOfBytesRecvd, NULL /* LPWSAOVERLAPPED */, NULL /* LPWSAOVERLAPPED_COMPLETION_ROUTINE */);
[build]       |     ^
[build] ../src/coap_io.c:987:9: warning: implicit declaration of function 'lpWSARecvMsg' [-Wimplicit-function-declaration]
[build]   987 |     r = lpWSARecvMsg(sock->fd, &mhdr, &dwNumberOfBytesRecvd, NULL /* LPWSAOVERLAPPED */, NULL /* LPWSAOVERLAPPED_COMPLETION_ROUTINE */);
[build]       |         ^~~~~~~~~~~~
[build] ../src/coap_io.c:987:40: error: 'dwNumberOfBytesRecvd' undeclared (first use in this function)
[build]   987 |     r = lpWSARecvMsg(sock->fd, &mhdr, &dwNumberOfBytesRecvd, NULL /* LPWSAOVERLAPPED */, NULL /* LPWSAOVERLAPPED_COMPLETION_ROUTINE */);
[build]       |                                        ^~~~~~~~~~~~~~~~~~~~
[build] ../src/coap_io.c:1021:17: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]  1021 |       for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) {
[build]       |                 ^
[build] ../src/coap_io.c:1021:54: warning: implicit declaration of function 'CMSG_NXTHDR'; did you mean 'WSA_CMSG_NXTHDR'? [-Wimplicit-function-declaration]
[build]  1021 |       for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) {
[build]       |                                                      ^~~~~~~~~~~
[build]       |                                                      WSA_CMSG_NXTHDR
[build] ../src/coap_io.c:1021:52: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]  1021 |       for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) {
[build]       |                                                    ^
[build] ../src/coap_io.c:1024:17: error: invalid use of undefined type 'struct cmsghdr'
[build]  1024 |         if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
[build]       |                 ^~
[build] ../src/coap_io.c:1024:53: error: invalid use of undefined type 'struct cmsghdr'
[build]  1024 |         if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
[build]       |                                                     ^~
[build] ../src/coap_io.c:1039:17: error: invalid use of undefined type 'struct cmsghdr'
[build]  1039 |         if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_PKTINFO) {
[build]       |                 ^~
[build] ../src/coap_io.c:1039:47: error: invalid use of undefined type 'struct cmsghdr'
[build]  1039 |         if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_PKTINFO) {
[build]       |                                               ^~
[build] ../src/coap_io.c:1071:19: error: invalid use of undefined type 'struct cmsghdr'
[build]  1071 |           if (cmsg->cmsg_level != -1 && cmsg->cmsg_type != -1) {
[build]       |                   ^~
[build] ../src/coap_io.c:1071:45: error: invalid use of undefined type 'struct cmsghdr'
[build]  1071 |           if (cmsg->cmsg_level != -1 && cmsg->cmsg_type != -1) {
[build]       |                                             ^~
[build] In file included from ../include/coap3/coap_net.h:37,
[build]                  from ../include/coap3/coap_async.h:20,
[build]                  from include/coap3/coap.h:47,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_io.c:16:
[build] ../src/coap_io.c:1074:26: error: invalid use of undefined type 'struct cmsghdr'
[build]  1074 |                      cmsg->cmsg_level, cmsg->cmsg_type);
[build]       |                          ^~
[build] ../include/coap3/coap_debug.h:220:29: note: in definition of macro 'coap_log'
[build]   220 |      coap_log_impl((level), __VA_ARGS__); \
[build]       |                             ^~~~~~~~~~~
[build] ../src/coap_io.c:1072:13: note: in expansion of macro 'coap_log_debug'
[build]  1072 |             coap_log_debug(
[build]       |             ^~~~~~~~~~~~~~
[build] ../src/coap_io.c:1074:44: error: invalid use of undefined type 'struct cmsghdr'
[build]  1074 |                      cmsg->cmsg_level, cmsg->cmsg_type);
[build]       |                                            ^~
[build] ../include/coap3/coap_debug.h:220:29: note: in definition of macro 'coap_log'
[build]   220 |      coap_log_impl((level), __VA_ARGS__); \
[build]       |                             ^~~~~~~~~~~
[build] ../src/coap_io.c:1072:13: note: in expansion of macro 'coap_log_debug'
[build]  1072 |             coap_log_debug(
[build]       |             ^~~~~~~~~~~~~~
[build] [12/36  22% :: 16.407] Building C object CMakeFiles/coap-3.dir/src/coap_hashkey.c.obj
[build] [12/36  25% :: 16.414] Building C object CMakeFiles/coap-3.dir/src/coap_mem.c.obj
[build] [12/36  27% :: 16.536] Building C object CMakeFiles/coap-3.dir/src/coap_event.c.obj
[build] [12/36  30% :: 16.593] Building C object CMakeFiles/coap-3.dir/src/coap_encode.c.obj
[build] [12/36  33% :: 16.685] Building C object CMakeFiles/coap-3.dir/src/coap_dtls.c.obj
[build] ninja: build stopped: subcommand failed.

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

As a comment, it would be helpful that any log files / debug files are included as an attached file, rather than long lists of information are embedded in the comments.

I am using your second version of MinGW.

For some reason your environment is detecting struct cmsghdr, but mine is not (I think because WIN32 is not set when using CMakeLists.txt) . I have

build-test/CMakeCache.txt:HAVE_STRUCT_CMSGHDR:INTERNAL=
build-test/coap_config.h:/* #undef HAVE_STRUCT_CMSGHDR */

and all works as expected.
Can you please try (initially in the libcoap directory

cmake -E remove_directory build-test
cmake -E make_directory build-test
cd build-test
cmake .. -DENABLE_DTLS=OFF -DENABLE_DOCS=OFF
cmake --build .

It would also be good to see the output of pacman -Q | sort (put into an attached file).

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

It is worth trying out this patch to see if that helps

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 12e9e17..70faf21 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -177,8 +177,12 @@ check_function_exists(getrandom HAVE_GETRANDOM)
 check_function_exists(random HAVE_RANDOM)
 check_function_exists(if_nametoindex HAVE_IF_NAMETOINDEX)

+if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
+       set(IS_MINGW 1)
+endif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
+
 # check for symbols
-if(WIN32)
+if(WIN32 AND NOT IS_MINGW)
   set(HAVE_STRUCT_CMSGHDR 1)
 else()
   check_symbol_exists(
@@ -468,10 +472,6 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h.in
                ${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h)


-if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
-       set(IS_MINGW 1)
-endif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
-
 #
 # sources
 #

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

It is worth trying out this patch to see if that helps

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 12e9e17..70faf21 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -177,8 +177,12 @@ check_function_exists(getrandom HAVE_GETRANDOM)
 check_function_exists(random HAVE_RANDOM)
 check_function_exists(if_nametoindex HAVE_IF_NAMETOINDEX)

+if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
+       set(IS_MINGW 1)
+endif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
+
 # check for symbols
-if(WIN32)
+if(WIN32 AND NOT IS_MINGW)
   set(HAVE_STRUCT_CMSGHDR 1)
 else()
   check_symbol_exists(
@@ -468,10 +472,6 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h.in
                ${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h)


-if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
-       set(IS_MINGW 1)
-endif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
-
 #
 # sources
 #

I tried this patch and found the same error after compiling

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

It would be good if you can give feedback on the things I raised in #1061 (comment) , it should help us to move forward.

[All I can think of is that in your version of sys/socket.h, CMSG_FIRSTHDR is defined, but not in my version as picked up in CMakeLists.txt]

I have updated #1062 to reflect the current state of where I have got to.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

@mrdeep1
image
Sorry, I may not have been clear in my last comment, I've tried it in #1062 and I find the same error is still reported.

cmake] Not searching for unused variables given on the command line.
[cmake] -- The CXX compiler identification is GNU 12.2.0
[cmake] -- The C compiler identification is GNU 12.2.0
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: D:/msys/mingw64/bin/g++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: D:/msys/mingw64/bin/gcc.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Looking for assert.h
[cmake] -- Looking for assert.h - found
[cmake] -- Looking for string.h
[cmake] -- Looking for string.h - found
[cmake] -- Looking for strings.h
[cmake] -- Looking for strings.h - found
[cmake] -- Looking for byteswap.h
[cmake] -- Looking for byteswap.h - not found
[cmake] -- Looking for inttypes.h
[cmake] -- Looking for inttypes.h - found
[cmake] -- Looking for errno.h
[cmake] -- Looking for errno.h - found
[cmake] -- Looking for limits.h
[cmake] -- Looking for limits.h - found
[cmake] -- Looking for memory.h
[cmake] -- Looking for memory.h - found
[cmake] -- Looking for sys/sysctl.h
[cmake] -- Looking for sys/sysctl.h - not found
[cmake] -- Looking for net/if.h
[cmake] -- Looking for net/if.h - not found
[cmake] -- Looking for netinet/in.h
[cmake] -- Looking for netinet/in.h - not found
[cmake] -- Looking for sys/epoll.h
[cmake] -- Looking for sys/epoll.h - not found
[cmake] -- Looking for sys/timerfd.h
[cmake] -- Looking for sys/timerfd.h - not found
[cmake] -- Looking for arpa/inet.h
[cmake] -- Looking for arpa/inet.h - not found
[cmake] -- Looking for stdbool.h
[cmake] -- Looking for stdbool.h - found
[cmake] -- Looking for netdb.h
[cmake] -- Looking for netdb.h - not found
[cmake] -- Looking for pthread.h
[cmake] -- Looking for pthread.h - found
[cmake] -- Looking for stdlib.h
[cmake] -- Looking for stdlib.h - found
[cmake] -- Looking for stdint.h
[cmake] -- Looking for stdint.h - found
[cmake] -- Looking for syslog.h
[cmake] -- Looking for syslog.h - not found
[cmake] -- Looking for sys/ioctl.h
[cmake] -- Looking for sys/ioctl.h - not found
[cmake] -- Looking for sys/socket.h
[cmake] -- Looking for sys/socket.h - not found
[cmake] -- Looking for sys/stat.h
[cmake] -- Looking for sys/stat.h - found
[cmake] -- Looking for sys/time.h
[cmake] -- Looking for sys/time.h - found
[cmake] -- Looking for sys/types.h
[cmake] -- Looking for sys/types.h - found
[cmake] -- Looking for sys/unistd.h
[cmake] -- Looking for sys/unistd.h - found
[cmake] -- Looking for time.h
[cmake] -- Looking for time.h - found
[cmake] -- Looking for unistd.h
[cmake] -- Looking for unistd.h - found
[cmake] -- Looking for float.h
[cmake] -- Looking for float.h - found
[cmake] -- Looking for stddef.h
[cmake] -- Looking for stddef.h - found
[cmake] -- Looking for winsock2.h
[cmake] -- Looking for winsock2.h - found
[cmake] -- Looking for ws2tcpip.h
[cmake] -- Looking for ws2tcpip.h - found
[cmake] -- Looking for malloc
[cmake] -- Looking for malloc - found
[cmake] -- Looking for memset
[cmake] -- Looking for memset - found
[cmake] -- Looking for select
[cmake] -- Looking for select - not found
[cmake] -- Looking for socket
[cmake] -- Looking for socket - not found
[cmake] -- Looking for strcasecmp
[cmake] -- Looking for strcasecmp - found
[cmake] -- Looking for pthread_mutex_lock
[cmake] -- Looking for pthread_mutex_lock - found
[cmake] -- Looking for getaddrinfo
[cmake] -- Looking for getaddrinfo - not found
[cmake] -- Looking for strnlen
[cmake] -- Looking for strnlen - found
[cmake] -- Looking for strrchr
[cmake] -- Looking for strrchr - found
[cmake] -- Looking for getrandom
[cmake] -- Looking for getrandom - not found
[cmake] -- compiling with client support
[cmake] -- compiling with server support
[cmake] -- compiling with OSCORE support
[cmake] -- compiling without epoll support
[cmake] -- compiling with DTLS support
[cmake] -- DTLS_BACKEND: default
[cmake] -- Could NOT find GnuTLS (missing: GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR) 
[cmake] -- Found OpenSSL: D:/Qt/Tools/OpenSSL/Win_x86/lib/libcrypto.lib (found version "1.1.1j")  
[cmake] -- compiling with openssl support
[cmake] -- PACKAGE VERSION..................4.3.1
[cmake] -- PACKAGE BUILD....................bsd-licensed-1732-gc8b265a-dirty
[cmake] -- ENABLE_DTLS:.....................ON
[cmake] -- ENABLE_TCP:......................ON
[cmake] -- ENABLE_CLIENT_MODE:..............ON
[cmake] -- ENABLE_SERVER_MODE:..............ON
[cmake] -- ENABLE_OSCORE:...................ON
[cmake] -- ENABLE_DOCS:.....................ON
[cmake] -- ENABLE_EXAMPLES:.................ON
[cmake] -- DTLS_BACKEND:....................default
[cmake] -- WITH_GNUTLS:.....................OFF
[cmake] -- WITH_TINYDTLS:...................OFF
[cmake] -- WITH_OPENSSL:....................ON
[cmake] -- WITH_MBEDTLS:....................OFF
[cmake] -- HAVE_LIBTINYDTLS:................
[cmake] -- HAVE_LIBGNUTLS:..................
[cmake] -- HAVE_OPENSSL:....................1
[cmake] -- HAVE_MBEDTLS:....................
[cmake] -- WITH_EPOLL:......................ON
[cmake] -- CMAKE_C_COMPILER:................D:/msys/mingw64/bin/gcc.exe
[cmake] -- BUILD_SHARED_LIBS:...............OFF
[cmake] -- CMAKE_BUILD_TYPE:................Release
[cmake] -- CMAKE_SYSTEM_PROCESSOR:..........AMD64
[cmake] -- WARNING_TO_ERROR:................OFF
[cmake] -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
[cmake] CMake Warning at CMakeLists.txt:714 (message):
[cmake]   Doxygen need to be installed to generate the doxygen documentation
[cmake] 
[cmake] 
[cmake] -- Configuring done
[cmake] CMake Warning (dev) at CMakeLists.txt:26 (add_library):
[cmake]   Policy CMP0115 is not set: Source file extensions must be explicit.  Run
[cmake]   "cmake --help-policy CMP0115" for policy details.  Use the cmake_policy
[cmake]   command to set the policy and suppress this warning.
[cmake] 
[cmake]   File:
[cmake] 
[cmake]     F:/project/learn/libcoap-minGW/libcoap/include/coap3/coap.h.in
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- Generating done
[cmake] -- Build files have been written to: F:/project/learn/libcoap-minGW/libcoap/build
[build] Starting build
[proc] Executing command: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --build f:/project/learn/libcoap-minGW/libcoap/build --config Release --target clean --
[build] [1/1 100% :: 0.494] Cleaning all built files...
[build] Cleaning... 0 files.
[build] Build finished with exit code 0
[main] Building folder: libcoap 
[build] Starting build
[proc] Executing command: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --build f:/project/learn/libcoap-minGW/libcoap/build --config Release --target coap-client --
[build] [6/36   2% :: 6.331] Building C object CMakeFiles/coap-3.dir/src/coap_mem.c.obj
[build] [7/36   5% :: 6.566] Building C object CMakeFiles/coap-3.dir/src/coap_async.c.obj
[build] [8/36   8% :: 6.572] Building C object CMakeFiles/coap-3.dir/src/coap_asn1.c.obj
[build] [9/36  11% :: 6.580] Building C object CMakeFiles/coap-3.dir/src/coap_cache.c.obj
[build] [10/36  13% :: 6.695] Building C object CMakeFiles/coap-3.dir/src/coap_address.c.obj
[build] [11/36  16% :: 6.786] Building C object CMakeFiles/coap-3.dir/src/coap_debug.c.obj
[build] [12/36  19% :: 11.885] Building C object CMakeFiles/coap-3.dir/src/coap_io.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_io.c.obj 
[build] D:\msys\mingw64\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-gc8b265a-dirty\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_io.c.obj -MF CMakeFiles\coap-3.dir\src\coap_io.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_io.c.obj -c ../src/coap_io.c
[build] ../src/coap_io.c: In function 'coap_socket_send':
[build] ../src/coap_io.c:744:14: warning: implicit declaration of function 'CMSG_SPACE'; did you mean 'C1_SPACE'? [-Wimplicit-function-declaration]
[build]   744 |     char buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
[build]       |              ^~~~~~~~~~
[build]       |              C1_SPACE
[build] ../src/coap_io.c:776:16: warning: implicit declaration of function 'CMSG_FIRSTHDR'; did you mean 'WSA_CMSG_FIRSTHDR'? [-Wimplicit-function-declaration]
[build]   776 |         cmsg = CMSG_FIRSTHDR(&mhdr);
[build]       |                ^~~~~~~~~~~~~
[build]       |                WSA_CMSG_FIRSTHDR
[build] ../src/coap_io.c:776:14: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]   776 |         cmsg = CMSG_FIRSTHDR(&mhdr);
[build]       |              ^
[build] ../src/coap_io.c:777:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   777 |         cmsg->cmsg_level = SOL_IP;
[build]       |             ^~
[build] ../src/coap_io.c:778:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   778 |         cmsg->cmsg_type = IP_PKTINFO;
[build]       |             ^~
[build] ../src/coap_io.c:779:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   779 |         cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
[build]       |             ^~
[build] ../src/coap_io.c:779:26: warning: implicit declaration of function 'CMSG_LEN' [-Wimplicit-function-declaration]
[build]   779 |         cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
[build]       |                          ^~~~~~~~
[build] ../src/coap_io.c:805:14: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]   805 |         cmsg = CMSG_FIRSTHDR(&mhdr);
[build]       |              ^
[build] ../src/coap_io.c:806:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   806 |         cmsg->cmsg_level = IPPROTO_IPV6;
[build]       |             ^~
[build] ../src/coap_io.c:807:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   807 |         cmsg->cmsg_type = IPV6_PKTINFO;
[build]       |             ^~
[build] ../src/coap_io.c:808:13: error: invalid use of undefined type 'struct cmsghdr'
[build]   808 |         cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
[build]       |             ^~
[build] ../src/coap_io.c:828:12: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]   828 |       cmsg = CMSG_FIRSTHDR(&mhdr);
[build]       |            ^
[build] ../src/coap_io.c:829:11: error: invalid use of undefined type 'struct cmsghdr'
[build]   829 |       cmsg->cmsg_level = SOL_IP;
[build]       |           ^~
[build] ../src/coap_io.c:830:11: error: invalid use of undefined type 'struct cmsghdr'
[build]   830 |       cmsg->cmsg_type = IP_PKTINFO;
[build]       |           ^~
[build] ../src/coap_io.c:831:11: error: invalid use of undefined type 'struct cmsghdr'
[build]   831 |       cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
[build]       |           ^~
[build] ../src/coap_io.c:872:21: warning: implicit declaration of function 'sendmsg' [-Wimplicit-function-declaration]
[build]   872 |     bytes_written = sendmsg(sock->fd, &mhdr, 0);
[build]       |                     ^~~~~~~
[build] ../src/coap_io.c: In function 'coap_socket_recv':
[build] ../src/coap_io.c:974:9: error: invalid use of undefined type 'struct cmsghdr'
[build]   974 |     cmsg->cmsg_len = CMSG_LEN(sizeof(buf));
[build]       |         ^~
[build] ../src/coap_io.c:975:9: error: invalid use of undefined type 'struct cmsghdr'
[build]   975 |     cmsg->cmsg_level = -1;
[build]       |         ^~
[build] ../src/coap_io.c:976:9: error: invalid use of undefined type 'struct cmsghdr'
[build]   976 |     cmsg->cmsg_type = -1;
[build]       |         ^~
[build] ../src/coap_io.c:979:10: error: 'lpWSARecvMsg' undeclared (first use in this function)
[build]   979 |     if (!lpWSARecvMsg) {
[build]       |          ^~~~~~~~~~~~
[build] ../src/coap_io.c:979:10: note: each undeclared identifier is reported only once for each function it appears in
[build] ../src/coap_io.c:987:5: error: 'r' undeclared (first use in this function)
[build]   987 |     r = lpWSARecvMsg(sock->fd, &mhdr, &dwNumberOfBytesRecvd, NULL /* LPWSAOVERLAPPED */, NULL /* LPWSAOVERLAPPED_COMPLETION_ROUTINE */);
[build]       |     ^
[build] ../src/coap_io.c:987:9: warning: implicit declaration of function 'lpWSARecvMsg' [-Wimplicit-function-declaration]
[build]   987 |     r = lpWSARecvMsg(sock->fd, &mhdr, &dwNumberOfBytesRecvd, NULL /* LPWSAOVERLAPPED */, NULL /* LPWSAOVERLAPPED_COMPLETION_ROUTINE */);
[build]       |         ^~~~~~~~~~~~
[build] ../src/coap_io.c:987:40: error: 'dwNumberOfBytesRecvd' undeclared (first use in this function)
[build]   987 |     r = lpWSARecvMsg(sock->fd, &mhdr, &dwNumberOfBytesRecvd, NULL /* LPWSAOVERLAPPED */, NULL /* LPWSAOVERLAPPED_COMPLETION_ROUTINE */);
[build]       |                                        ^~~~~~~~~~~~~~~~~~~~
[build] ../src/coap_io.c:1021:17: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]  1021 |       for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) {
[build]       |                 ^
[build] ../src/coap_io.c:1021:54: warning: implicit declaration of function 'CMSG_NXTHDR'; did you mean 'WSA_CMSG_NXTHDR'? [-Wimplicit-function-declaration]
[build]  1021 |       for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) {
[build]       |                                                      ^~~~~~~~~~~
[build]       |                                                      WSA_CMSG_NXTHDR
[build] ../src/coap_io.c:1021:52: warning: assignment to 'struct cmsghdr *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
[build]  1021 |       for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) {
[build]       |                                                    ^
[build] ../src/coap_io.c:1024:17: error: invalid use of undefined type 'struct cmsghdr'
[build]  1024 |         if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
[build]       |                 ^~
[build] ../src/coap_io.c:1024:53: error: invalid use of undefined type 'struct cmsghdr'
[build]  1024 |         if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
[build]       |                                                     ^~
[build] ../src/coap_io.c:1039:17: error: invalid use of undefined type 'struct cmsghdr'
[build]  1039 |         if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_PKTINFO) {
[build]       |                 ^~
[build] ../src/coap_io.c:1039:47: error: invalid use of undefined type 'struct cmsghdr'
[build]  1039 |         if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_PKTINFO) {
[build]       |                                               ^~
[build] ../src/coap_io.c:1071:19: error: invalid use of undefined type 'struct cmsghdr'
[build]  1071 |           if (cmsg->cmsg_level != -1 && cmsg->cmsg_type != -1) {
[build]       |                   ^~
[build] ../src/coap_io.c:1071:45: error: invalid use of undefined type 'struct cmsghdr'
[build]  1071 |           if (cmsg->cmsg_level != -1 && cmsg->cmsg_type != -1) {
[build]       |                                             ^~
[build] In file included from ../include/coap3/coap_net.h:37,
[build]                  from ../include/coap3/coap_async.h:20,
[build]                  from include/coap3/coap.h:47,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_io.c:16:
[build] ../src/coap_io.c:1074:26: error: invalid use of undefined type 'struct cmsghdr'
[build]  1074 |                      cmsg->cmsg_level, cmsg->cmsg_type);
[build]       |                          ^~
[build] ../include/coap3/coap_debug.h:220:29: note: in definition of macro 'coap_log'
[build]   220 |      coap_log_impl((level), __VA_ARGS__); \
[build]       |                             ^~~~~~~~~~~
[build] ../src/coap_io.c:1072:13: note: in expansion of macro 'coap_log_debug'
[build]  1072 |             coap_log_debug(
[build]       |             ^~~~~~~~~~~~~~
[build] ../src/coap_io.c:1074:44: error: invalid use of undefined type 'struct cmsghdr'
[build]  1074 |                      cmsg->cmsg_level, cmsg->cmsg_type);
[build]       |                                            ^~
[build] ../include/coap3/coap_debug.h:220:29: note: in definition of macro 'coap_log'
[build]   220 |      coap_log_impl((level), __VA_ARGS__); \
[build]       |                             ^~~~~~~~~~~
[build] ../src/coap_io.c:1072:13: note: in expansion of macro 'coap_log_debug'
[build]  1072 |             coap_log_debug(
[build]       |             ^~~~~~~~~~~~~~

Also, there is no sys/socket.h file in my environment, is there something wrong with my mingw?
image

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

As requested, can you please provide the output from, so that we can see the difference between your development environment and mine.

pacman -Q | sort

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

As requested, can you please provide the output from, so that we can see the difference between your development environment and mine.

pacman -Q | sort

MINGW64 ~
$ pacman -Q | sort

base 2022.06-1
bash 5.2.015-1
bash-completion 2.11-3
brotli 1.0.9-8
bsdtar 3.6.2-3
bzip2 1.0.8-4
ca-certificates 20230311-1
coreutils 8.32-5
curl 7.88.1-1
dash 0.5.12-1
db 5.3.28-4
file 5.44-5
filesystem 2023.02.07-1
findutils 4.9.0-3
gawk 5.2.1-2
gcc-libs 11.3.0-3
gdbm 1.23-1
getent 2.18.90-4
gettext 0.21-2
gmp 6.2.1-2
gnupg 2.2.41-1
grep 1~3.0-6
gzip 1.12-2
heimdal-libs 7.8.0-3
inetutils 2.4-1
info 7.0.2-1
less 629-1
libargp 20110921-4
libasprintf 0.21-2
libassuan 2.5.5-2
libbz2 1.0.8-4
libcrypt 2.1-4
libcurl 7.88.1-1
libdb 5.3.28-4
libedit 20221030_3.1-1
libexpat 2.5.0-1
libffi 3.4.4-1
libgcrypt 1.10.1-5
libgdbm 1.23-1
libgettextpo 0.21-2
libgnutls 3.8.0-1
libgpg-error 1.46-2
libgpgme 1.18.0-4
libhogweed 3.8.1-1
libiconv 1.17-1
libidn2 2.3.4-2
libintl 0.21-2
libksba 1.6.3-1
liblz4 1.9.4-1
liblzma 5.4.1-1
libnettle 3.8.1-1
libnghttp2 1.52.0-1
libnpth 1.6-1
libopenssl 3.1.0-1
libp11-kit 0.24.1-4
libpcre 8.45-3
libpcre2_8 10.42-1
libpsl 0.21.2-1
libreadline 8.2.001-3
libsqlite 3.41.1-1
libssh2 1.10.0-3
libtasn1 4.19.0-1
libunistring 1.1-2
libutil-linux 2.35.2-3
libxml2 2.10.3-3
libxslt 1.1.37-1
libzstd 1.5.4-1
mingw-w64-x86_64-binutils 2.40-2
mingw-w64-x86_64-bzip2 1.0.8-2
mingw-w64-x86_64-crt-git 10.0.0.r234.g283e5b23a-1
mingw-w64-x86_64-expat 2.5.0-1
mingw-w64-x86_64-gcc 12.2.0-10
mingw-w64-x86_64-gcc-ada 12.2.0-10
mingw-w64-x86_64-gcc-fortran 12.2.0-10
mingw-w64-x86_64-gcc-libgfortran 12.2.0-10
mingw-w64-x86_64-gcc-libs 12.2.0-10
mingw-w64-x86_64-gcc-objc 12.2.0-10
mingw-w64-x86_64-gdb 13.1-3
mingw-w64-x86_64-gdb-multiarch 13.1-3
mingw-w64-x86_64-gettext 0.21.1-1
mingw-w64-x86_64-gmp 6.2.1-5
mingw-w64-x86_64-headers-git 10.0.0.r234.g283e5b23a-1
mingw-w64-x86_64-isl 0.25-1
mingw-w64-x86_64-libffi 3.4.4-1
mingw-w64-x86_64-libgccjit 12.2.0-10
mingw-w64-x86_64-libiconv 1.17-3
mingw-w64-x86_64-libmangle-git 10.0.0.r234.g283e5b23a-1
mingw-w64-x86_64-libsystre 1.0.1-4
mingw-w64-x86_64-libtre-git r128.6fb7206-2
mingw-w64-x86_64-libwinpthread-git 10.0.0.r234.g283e5b23a-1
mingw-w64-x86_64-make 4.4-2
mingw-w64-x86_64-mpc 1.3.1-1
mingw-w64-x86_64-mpdecimal 2.5.1-1
mingw-w64-x86_64-mpfr 4.2.0-1
mingw-w64-x86_64-ncurses 6.4.20230211-1
mingw-w64-x86_64-openssl 3.1.0-1
mingw-w64-x86_64-pkgconf 1~1.8.0-2
mingw-w64-x86_64-python 3.10.10-1
mingw-w64-x86_64-readline 8.2.001-6
mingw-w64-x86_64-sqlite3 3.41.1-1
mingw-w64-x86_64-tcl 8.6.12-1
mingw-w64-x86_64-termcap 1.3.1-6
mingw-w64-x86_64-tk 8.6.12-1
mingw-w64-x86_64-tools-git 10.0.0.r234.g283e5b23a-1
mingw-w64-x86_64-tzdata 2022g-1
mingw-w64-x86_64-windows-default-manifest 6.4-4
mingw-w64-x86_64-winpthreads-git 10.0.0.r234.g283e5b23a-1
mingw-w64-x86_64-winstorecompat-git 10.0.0.r234.g283e5b23a-1
mingw-w64-x86_64-xxhash 0.8.1-2
mingw-w64-x86_64-xz 5.4.1-1
mingw-w64-x86_64-zlib 1.2.13-3
mingw-w64-x86_64-zstd 1.5.4-1
mintty 1~3.6.3-1
mpfr 4.2.0-2
msys2-keyring 1~20230316-1
msys2-launcher 1.5-1
msys2-runtime 3.4.6-1
nano 7.2-1
ncurses 6.4-1
nettle 3.8.1-1
openssl 3.1.0-1
p11-kit 0.24.1-4
pacman 6.0.2-1
pacman-contrib 1.8.2-1
pacman-mirrors 20221016-1
perl 5.36.0-1
pinentry 1.2.1-1
rebase 4.5.0-2
sed 4.9-1
tar 1.34-3
tcl 8.6.12-1
time 1.9-3
tzcode 2022g-1
util-linux 2.35.2-3
wget 1.21.3-2
which 2.21-4
xz 5.4.1-1
zlib 1.2.13-1
zstd 1.5.4-1

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

There are a fair number of differences in the packages (
mingw-diff.txt
). I suspect the main one you need could be msys2-runtime-devel which is required by my version of gcc followed possibly by msys2-w32api-headers and msys2-w32api-runtime.

You can also try making this change to see how much further you get into the compilation

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4c0acb8..9fbf008 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -185,7 +185,7 @@ else()
   check_symbol_exists(
     CMSG_FIRSTHDR
     sys/socket.h
-    HAVE_STRUCT_CMSGHDR)
+    HAVE_STRUCT_CMSGHDR_ignore)
 endif()
 
 if(${ENABLE_CLIENT_MODE})

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

There are a fair number of differences in the packages ( mingw-diff.txt ). I suspect the main one you need could be msys2-runtime-devel which is required by my version of gcc followed possibly by msys2-w32api-headers and msys2-w32api-runtime.

You can also try making this change to see how much further you get into the compilation

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4c0acb8..9fbf008 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -185,7 +185,7 @@ else()
   check_symbol_exists(
     CMSG_FIRSTHDR
     sys/socket.h
-    HAVE_STRUCT_CMSGHDR)
+    HAVE_STRUCT_CMSGHDR_ignore)
 endif()
 
 if(${ENABLE_CLIENT_MODE})

Sadly, it didn't work

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

There are a fair number of differences in the packages ( mingw-diff.txt ). I suspect the main one you need could be msys2-runtime-devel which is required by my version of gcc followed possibly by msys2-w32api-headers and msys2-w32api-runtime.

You can also try making this change to see how much further you get into the compilation

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4c0acb8..9fbf008 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -185,7 +185,7 @@ else()
   check_symbol_exists(
     CMSG_FIRSTHDR
     sys/socket.h
-    HAVE_STRUCT_CMSGHDR)
+    HAVE_STRUCT_CMSGHDR_ignore)
 endif()
 
 if(${ENABLE_CLIENT_MODE})

The sys/socket.h header file is part of the POSIX standard and is not normally available in the Windows environment. minGW does not include this header file because it is primarily intended to provide a minimal GNU environment for Windows.

Your environment has this file?

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

I am assuming that you have now installed the package msys2-runtime-devel using pacman -S msys2-runtime-devel, as well as the other suggested packages in my previous comment.

Please try making these changes.

diff --git a/src/coap_io.c b/src/coap_io.c
index d1d1cf6..6de4e7d 100644
--- a/src/coap_io.c
+++ b/src/coap_io.c
@@ -739,7 +739,7 @@ coap_socket_send(coap_socket_t *sock, const coap_session_t *session, const uint8
     DWORD dwNumberOfBytesSent = 0;
     int r;
 #endif /* _WIN32 && !__MINGW32__ */
-#ifdef HAVE_STRUCT_CMSGHDR
+#ifdef HAVE_STRUCT_CMSGHDRa
     /* a buffer large enough to hold all packet info types, ipv6 is the largest */
     char buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
     struct msghdr mhdr;
@@ -868,7 +868,7 @@ coap_socket_send(coap_socket_t *sock, const coap_session_t *session, const uint8
     else
       bytes_written = -1;
 #else /* !_WIN32 || __MINGW32__ */
-#ifdef HAVE_STRUCT_CMSGHDR
+#ifdef HAVE_STRUCT_CMSGHDRa
     bytes_written = sendmsg(sock->fd, &mhdr, 0);
 #else /* ! HAVE_STRUCT_CMSGHDR */
     bytes_written = sendto(sock->fd, (const void*)data, datalen, 0,
@@ -948,7 +948,7 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) {
     DWORD dwNumberOfBytesRecvd = 0;
     int r;
 #endif /* _WIN32 && !__MINGW32__ */
-#ifdef HAVE_STRUCT_CMSGHDR
+#ifdef HAVE_STRUCT_CMSGHDRa
     /* a buffer large enough to hold all packet info types, ipv6 is the largest */
     char buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
     struct cmsghdr *cmsg;
@@ -1010,7 +1010,7 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) {
       coap_log_warn("coap_socket_recv: %s\n", coap_socket_strerror());
       goto error;
     } else {
-#ifdef HAVE_STRUCT_CMSGHDR
+#ifdef HAVE_STRUCT_CMSGHDRa
       int dst_found = 0;

       packet->addr_info.remote.size = mhdr.msg_namelen;

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

@mrdeep1
Interestingly, I have two mingw compilers, and I get different errors building libcoap with each of them.
MinGW 9.2.0

[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-gc8b265a-dirty\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_mem.c.obj -MF CMakeFiles\coap-3.dir\src\coap_mem.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_mem.c.obj -c ../src/coap_mem.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_mem.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_mem.c:16:
[build] ../include/coap3/libcoap.h:34:17: note: previous declaration of 'ssize_t' was here
[build]    34 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] [6/34   5% :: 2.903] Building C object CMakeFiles/coap-3.dir/src/coap_asn1.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_asn1.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-gc8b265a-dirty\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_asn1.c.obj -MF CMakeFiles\coap-3.dir\src\coap_asn1.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_asn1.c.obj -c ../src/coap_asn1.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_asn1.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_asn1.c:16:
[build] ../include/coap3/libcoap.h:34:17: note: previous declaration of 'ssize_t' was here
[build]    34 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] [6/34   8% :: 3.026] Building C object CMakeFiles/coap-3.dir/src/coap_debug.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_debug.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-gc8b265a-dirty\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_debug.c.obj -MF CMakeFiles\coap-3.dir\src\coap_debug.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_debug.c.obj -c ../src/coap_debug.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_debug.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_debug.c:16:
[build] ../include/coap3/libcoap.h:34:17: note: previous declaration of 'ssize_t' was here
[build]    34 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] ../src/coap_debug.c: In function 'coap_print_addr':
[build] ../src/coap_debug.c:251:7: warning: implicit declaration of function 'inet_ntop'; did you mean 'inet_ntoa'? [-Wimplicit-function-declaration]
[build]   251 |   if (inet_ntop(addr->addr.sa.sa_family, addrptr, (char *)p,
[build]       |       ^~~~~~~~~
[build]       |       inet_ntoa
[build] [6/34  11% :: 3.039] Building C object CMakeFiles/coap-3.dir/src/coap_address.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_address.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-gc8b265a-dirty\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_address.c.obj -MF CMakeFiles\coap-3.dir\src\coap_address.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_address.c.obj -c ../src/coap_address.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_address.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_address.c:16:
[build] ../include/coap3/libcoap.h:34:17: note: previous declaration of 'ssize_t' was here
[build]    34 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] ../src/coap_address.c: In function 'coap_resolve_address_info':
[build] ../src/coap_address.c:226:11: warning: implicit declaration of function 'getaddrinfo' [-Wimplicit-function-declaration]
[build]   226 |   error = getaddrinfo(addrstr, NULL, &hints, &res);
[build]       |           ^~~~~~~~~~~
[build] ../src/coap_address.c:366:3: warning: implicit declaration of function 'freeaddrinfo' [-Wimplicit-function-declaration]
[build]   366 |   freeaddrinfo(res);
[build]       |   ^~~~~~~~~~~~
[build] [6/34  14% :: 3.046] Building C object CMakeFiles/coap-3.dir/src/coap_async.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_async.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-gc8b265a-dirty\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_async.c.obj -MF CMakeFiles\coap-3.dir\src\coap_async.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_async.c.obj -c ../src/coap_async.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_async.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_async.c:16:
[build] ../include/coap3/libcoap.h:34:17: note: previous declaration of 'ssize_t' was here
[build]    34 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] [6/34  17% :: 3.062] Building C object CMakeFiles/coap-3.dir/src/coap_cache.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_cache.c.obj 
[build] D:\MinGW\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"bsd-licensed-1732-gc8b265a-dirty\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_cache.c.obj -MF CMakeFiles\coap-3.dir\src\coap_cache.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_cache.c.obj -c ../src/coap_cache.c
[build] In file included from ../include/coap3/coap_address.h:23,
[build]                  from include/coap3/coap.h:46,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_cache.c:16:
[build] d:\mingw\include\sys\types.h:123:21: error: conflicting types for 'ssize_t'
[build]   123 |   typedef _ssize_t  ssize_t;
[build]       |                     ^~~~~~~
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_cache.c:16:
[build] ../include/coap3/libcoap.h:34:17: note: previous declaration of 'ssize_t' was here
[build]    34 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] ninja: build stopped: subcommand failed.

The other one is installed via msys
error: CMSG_FIRSTHDR

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

The sys/socket.h header file is part of the POSIX standard and is not normally available in the Windows environment. minGW does not include this header file because it is primarily intended to provide a minimal GNU environment for Windows.

Your environment has this file?

Yes, my environment has sys/socket.h - from the package msys2-runtime-devel.

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

Interestingly, I have two mingw compilers, and I get different errors building libcoap with each of them.
MinGW 9.2.0

The ssizet_t issue has been fixed in the latest (forced update) version of #1062 as per fix I previously suggested

diff --git a/include/coap3/libcoap.h b/include/coap3/libcoap.h
index d7fcc13..5a2bdcd 100644
--- a/include/coap3/libcoap.h
+++ b/include/coap3/libcoap.h
@@ -30,8 +30,14 @@
 #pragma comment(lib,"Ws2_32.lib")
 #endif /* !defined(__MINGW32__) */
 #include <ws2tcpip.h>
+#ifndef _SSIZE_T_DECLARED
 typedef SSIZE_T ssize_t;
+#define        _SSIZE_T_DECLARED
+#endif
+#ifndef _IN_PORT_T_DECLARED
 typedef USHORT in_port_t;
+#define        _IN_PORT_T_DECLARED
+#endif
 #elif !defined (CONTIKI) && !defined (WITH_LWIP)
 #include <netinet/in.h>
 #include <sys/socket.h>

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024
$ pacman -S msys2-runtime-devel
resolving dependencies...
looking for conflicting packages...

Packages (1) msys2-runtime-devel-3.4.6-1

Total Download Size:   0.33 MiB
Total Installed Size:  4.12 MiB

:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 msys2-runtime-devel-3.4.6-...   338.2 KiB   210 KiB/s 00:02 [###############################] 100%
(1/1) checking keys in keyring                               [###############################] 100%
(1/1) checking package integrity                             [###############################] 100%
(1/1) loading package files                                  [###############################] 100%
(1/1) checking for file conflicts                            [###############################] 100%
(1/1) checking available disk space                          [###############################] 100%
:: Processing package changes...
(1/1) installing msys2-runtime-devel                         [###############################] 100%

 MINGW64 ~
$ gcc -v
Using built-in specs.
COLLECT_GCC=D:\msys\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-12.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --buil
d=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-head
er-dir=/mingw64/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --wit
h-arch=nocona --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable
-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-d
ynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --ena
ble-lto --enable-libgomp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls -
-disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr
=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev10, Built by MSYS2 project'
--with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-l
ibstdcxx-debug --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Rev10, Built by MSYS2 project)

#1062 update I also tried, ssize_t problem seems to report the same error, now I have given up the first compiler.


This is really weird, I'm sure I have msys2-runtime-devel installed, but I don't have this file. Ok, I will now try the change you mentioned in the second compiler

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

@mrdeep1
OMG, the compilation passed! But only the compile target is libcoap-3, other compile targets are not passed, such as install, coap-rd, coap-client, etc.

[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libcoap-3.a(coap_openssl.c.obj):coap_openssl.c:(.text+0x50e1): undefined reference to `EVP_DigestUpdate'
[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libcoap-3.a(coap_openssl.c.obj):coap_openssl.c:(.rdata$.refptr.EVP_sha384[.refptr.EVP_sha384]+0x0): undefined reference to `EVP_sha384'
[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libcoap-3.a(coap_openssl.c.obj):coap_openssl.c:(.rdata$.refptr.EVP_sha256[.refptr.EVP_sha256]+0x0): undefined reference to `EVP_sha256'
[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libcoap-3.a(coap_openssl.c.obj):coap_openssl.c:(.rdata$.refptr.EVP_sha512[.refptr.EVP_sha512]+0x0): undefined reference to `EVP_sha512'
[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libcoap-3.a(coap_openssl.c.obj):coap_openssl.c:(.rdata$.refptr.EVP_aes_128_ccm[.refptr.EVP_aes_128_ccm]+0x0): undefined reference to `EVP_aes_128_ccm'
[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libcoap-3.a(coap_openssl.c.obj):coap_openssl.c:(.rdata$.refptr.EVP_aes_256_ccm[.refptr.EVP_aes_256_ccm]+0x0): undefined reference to `EVP_aes_256_ccm'
[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libcoap-3.a(coap_openssl.c.obj):coap_openssl.c:(.rdata$.refptr.GENERAL_NAME_free[.refptr.GENERAL_NAME_free]+0x0): undefined reference to `GENERAL_NAME_free'
[build] collect2.exe: error: ld returned 1 exit status

I think there is no link to the ws2_32 library

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

The OpenSSL library is missing some functionality. I am not at my desk at present, but it looks like the functions are used by the OSCORE build, so you can try turning OSCORE build off (something like -DWITH_OSCORE=OFF as a parameter) when setting up cmake. Alternatively, try turning off DTLS.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

Also, I don't know if you've tried MSVC after the change, but I found a place where the definition is not very accurate and causes compilation exceptions.
The mhdr definition is here:

#ifdef HAVE_STRUCT_CMSGHDRa
    /* a buffer large enough to hold all packet info types, ipv6 is the largest */
    char buf[CMSG_SPACE(sizeof(struct in6_pktinfo))].
    struct cmsghdr *cmsg.
    struct msghdr mhdr.

means that mhdr should only be related to HAVE_STRUCT_CMSGHDRa

#if defined(_WIN32) && !defined(__MINGW32__)
    r = WSASendMsg(sock->fd, &mhdr, 0 /*dwFlags*/, &dwNumberOfBytesSent, NULL /*lpOverlapped*/, NULL /*lpCompletionRoutine*/).
    if (r == 0)
      bytes_written = (ssize_t)dwNumberOfBytesSent.
    else
      bytes_written = -1.
#else /* ! _WIN32 || __MINGW32__ */

But there is a reference to mhdr here, in which case I will get an exception when compiling with MSVC: undeclared identifier

[build] ... \src\coap_io.c(865): error C2065: "mhdr": undeclared identifier
[build] ... \src\coap_io.c(865): warning C4133: "function": from "int *" to "LPWSAMSG" Type incompatibility

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

This fix is an easy workaround for you to test MinGW specifically , and will fail in all other build environments - hence your MSVC issue.

what I do not understand is why you are somehow getting HAVE_STRUCT_CMSGHDR defined which the primary cause of your MinGW failure, not mine.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

This fix is an easy workaround for you to test MinGW specifically , and will fail in all other build environments - hence your MSVC issue.

what I do not understand is why you are somehow getting HAVE_STRUCT_CMSGHDR defined which the primary cause of your MinGW failure, not mine.

Well, looks like I'll have to look into why I found the definition of HAVE_STRUCT_CMSGHDR, thanks for the help.

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

Can you please try the latest code in #1062 - which has been force pushed. The easiest thing may be to delete the libcoap directory and re-clone it form the mrdeep1 repository (and remember to change the branch to mingw).

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

image
@mrdeep1 Is this the branch you are referring to? Is the time March 30th?

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

That version has the code changes in it. I have just pushed a rebased off the develop branch version to PR #1062 so everything is consistent. It has the hash f1c3d95

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

That version has the code changes in it. I have just pushed a rebased off the develop branch version to PR #1062 so everything is consistent. It has the hash f1c3d95

I've been using this version #1062, I don't understand what you mean?

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

PR #1062 code has been updated (in git terms, a forced update), and you need to have the latest version of code which has a hash of f1c3d95. The March 30 date is when I first created the patch and that does not change.

The cmake summary shows the hash as

[cmake] -- PACKAGE BUILD....................??????????-gXXXXXXX

where XXXXXXX should be f1c3d95 (there is a leading g). Alternatively, you can try running git describe --tags and looking at that output.

As said before, the easiest thing may be to delete the libcoap directory and re-clone it form the mrdeep1 repository (and remember to change the branch to mingw) to make sure that you have the latest code in PR #1062.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

I tried the latest code in #1062 as you said. Still have my old problem

 error: invalid use of undefined type 'struct cmsghdr'

Then I replaced HAVE_STRUCT_CMSGHDR with HAVE_STRUCT_CMSGHDRa and the target for coap-3 built successfully, but the other targets failed:

[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/coap-rd.dir/examples/coap-rd.c.obj:coap-rd.c:(.text+0xa3d): undefined reference to `__imp_htons'
[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/coap-rd.dir/examples/coap-rd.c.obj:coap-rd.c:(.text.startup+0x571): undefined reference to `__imp_getaddrinfo'
[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/coap-rd.dir/examples/coap-rd.c.obj:coap-rd.c:(.text.startup+0x5d7): undefined reference to `__imp_freeaddrinfo'
[build] D:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/coap-rd.dir/examples/coap-rd.c.obj:coap-rd.c:(.text.startup+0x934): undefined reference to `__imp_ntohs'

This error prints close to a thousand lines


Then I do not enable OSCORE, Found to introduce some new errors:
image

[build] FAILED: CMakeFiles/coap-3.dir/src/coap_ws.c.obj 
[build] D:\msys\mingw64\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"v4.3.1-131-gf1c3d95-dirty\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_ws.c.obj -MF CMakeFiles\coap-3.dir\src\coap_ws.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_ws.c.obj -c ../src/coap_ws.c
[build] ../src/coap_ws.c: In function 'coap_ws_build_key_hash':
[build] ../src/coap_ws.c:403:8: warning: implicit declaration of function 'coap_crypto_hash'; did you mean 'coap_str_hash'? [-Wimplicit-function-declaration]
[build]   403 |   if (!coap_crypto_hash(COSE_ALGORITHM_SHA_1, &info, &hashed))
[build]       |        ^~~~~~~~~~~~~~~~
[build]       |        coap_str_hash
[build] ../src/coap_ws.c:403:25: error: 'COSE_ALGORITHM_SHA_1' undeclared (first use in this function); did you mean 'DSA_HASH_ALGORITHM_SHA1'?
[build]   403 |   if (!coap_crypto_hash(COSE_ALGORITHM_SHA_1, &info, &hashed))
[build]       |                         ^~~~~~~~~~~~~~~~~~~~
[build]       |                         DSA_HASH_ALGORITHM_SHA1
[build] ../src/coap_ws.c:403:25: note: each undeclared identifier is reported only once for each function it appears in

Looks the same as the last change

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

Have found the primary difference in packages between our build environments - cmake v mingw-w64-ucrt-x86_64-cmake. The latter (which you were using) changed the CMAKE_HOST_SYSTEM_NAME variable from MINGW64_xxxxx to Windows. This then caused the CMakeLists.txt file to get confused, and I have now reproduced (and fixed) what you were seeing.

Updated CMakeLists.txt and BUILDING files (force) pushed to #1062. Please try out the latest code.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

Have found the primary difference in packages between our build environments - cmake v mingw-w64-ucrt-x86_64-cmake. The latter (which you were using) changed the CMAKE_HOST_SYSTEM_NAME variable from MINGW64_xxxxx to Windows. This then caused the CMakeLists.txt file to get confused, and I have now reproduced (and fixed) what you were seeing.

Updated CMakeLists.txt and BUILDING files (force) pushed to #1062. Please try out the latest code.

Great, here's the solution to the HAVE_STRUCT_CMSGHDR problem.And then the problem with the ws2_32 library is solved!

diff --git "a/CMakeLists.txt" "b/CMakeLists.txt"
index 74fc95d..2b3f295 100644
--- "a/CMakeLists.txt"
+++ "b/CMakeLists.txt"
@@ -180,14 +180,11 @@ check_function_exists(getrandom HAVE_GETRANDOM)
 check_function_exists(random HAVE_RANDOM)
 check_function_exists(if_nametoindex HAVE_IF_NAMETOINDEX)
 
-if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
-	set(IS_MINGW 1)
-endif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "^MINGW")
 # Check the symbols
-if(WIN32)
+if(WIN32 AND NOT MINGW)
   set(HAVE_STRUCT_CMSGHDR 1)
-elseif (NOT IS_MINGW)
+ message(STATUS "setting HAVE_STRUCT_CMSGHDR")
+else()
   check_symbol_exists(
     CMSG_FIRSTHDR
     sys/socket.h

 set(top_srcdir "${CMAKE_CURRENT_LIST_DIR}")
@@ -569,7 +567,7 @@ target_link_libraries(
          $<$<BOOL:${HAVE_MBEDTLS}>:${MBEDTLS_LIBRARY}>
          $<$<BOOL:${HAVE_MBEDTLS}>:${MBEDX509_LIBRARY}>
          $<$<BOOL:${HAVE_MBEDTLS}>:${MBEDCRYPTO_LIBRARY}>
-         $<$<BOOL:${IS_MINGW}>:ws2_32>)
+         $<$<BOOL:${MINGW}>:ws2_32>)

Finally I have a doubt, as far as I know, openssl is a pure C library and when the libcoap project introduces openssl (compiled by MSVC), it is logical that it will compile with either MinGW compilation or MSVC compilation. But the reality is that I got an error when compiling with MinGW, so I had to compile a new openssl library using MinGW. This was the only way to get my libcoap project to pass using MinGW. This disproves my previous suspicion, so I would like to ask you if your libcoap project also references the openssl compiled by MinGW in order to compile with MinGW?

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

If you use the MinGW packages described in the latest #1062 BUILDING file (at the end) in particular the OpenSSL one instead of your compiled one, you will find that all works as expected.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

I downloaded the mingw-x86 version from msys2 and I tried to build it and I found this error:

[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_asn1.c:16:
[build] ../include/coap3/libcoap.h:34:17: error: conflicting types for 'ssize_t'; have 'SSIZE_T' {aka 'long int'}
[build]    34 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] In file included from D:/msys/mingw32/include/crtdefs.h:10,
[build]                  from D:/msys/mingw32/include/assert.h:15,
[build]                  from ../include/coap3/coap_internal.h:35:
[build] D:/msys/mingw32/include/corecrt.h:47:13: note: previous declaration of 'ssize_t' with type 'ssize_t' {aka 'int'}
[build]    47 | typedef int ssize_t;
[build]       |             ^~~~~~~
[build] [6/40   5% :: 2.201] Building C object CMakeFiles/coap-3.dir/src/coap_dtls.c.obj
[build] FAILED: CMakeFiles/coap-3.dir/src/coap_dtls.c.obj 
[build] D:\msys\mingw32\bin\gcc.exe  -I. -Iinclude -I../include -isystem D:/Qt/Tools/OpenSSL/Win_x86/include -O3 -DNDEBUG -DLIBCOAP_PACKAGE_BUILD=\"v4.3.1-132-g39c19bc\" -std=gnu99 -MD -MT CMakeFiles/coap-3.dir/src/coap_dtls.c.obj -MF CMakeFiles\coap-3.dir\src\coap_dtls.c.obj.d -o CMakeFiles/coap-3.dir/src/coap_dtls.c.obj -c ../src/coap_dtls.c
[build] In file included from include/coap3/coap.h:43,
[build]                  from ../include/coap3/coap_internal.h:74,
[build]                  from ../src/coap_dtls.c:18:
[build] ../include/coap3/libcoap.h:34:17: error: conflicting types for 'ssize_t'; have 'SSIZE_T' {aka 'long int'}
[build]    34 | typedef SSIZE_T ssize_t;
[build]       |                 ^~~~~~~
[build] In file included from D:/msys/mingw32/include/crtdefs.h:10,
[build]                  from D:/msys/mingw32/include/assert.h:15,
[build]                  from ../include/coap3/coap_internal.h:35:
[build] D:/msys/mingw32/include/corecrt.h:47:13: note: previous declaration of 'ssize_t' with type 'ssize_t' {aka 'int'}
[build]    47 | typedef int ssize_t;
[build]       |             ^~~~~~~
[build] [6/40   7% :: 2.212] Building C object CMakeFiles/coap-3.dir/src/coap_address.c.obj

I confirm that I am using the latest code. Have you tried compiling with the MinGW-x86 compiler?
image

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

There is now a GitHub workflow for building MinGW - see https://github.com/obgm/libcoap/actions/runs/4668101581/jobs/8264727046 . This workflow successfully builds MinGW with OpenSSL and essentially follows the build instructions in BUILDING. I would say your MSYS2 environment is polluted with all your testing and you need to start from a fresh install of MSYS2.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

You only mentioned the compilation environment for mingw-x64, and I have no problem compiling with 64-bit. The problem is building libcoap in a 32-bit (i686) compiler.
I don't think I have any problem with my mingw32 because I installed the 32-bit (i686) compiler for MinGW-w64 in the morning. It is not contaminated and is brand new
pacman -S mingw-w64-i686-toolchain
Have you tried compiling with i686-w64-ming32?

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

Have you tried compiling with i686-w64-ming32?

No. I will try it out later.

Good that you have confirmed that the x86_64 MinGW build is now fine for libcoap + OpenSSL.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

Now all that is missing is the compilation of i686-w64-ming32
Thanks to the fact that I built an openssl library yesterday using MinGW, I was able to get a one-time build through when I got your latest #1062.
In addition, You're amazing! Your programming skills are incredible. Thank you!

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

Can you please try making these changes

diff --git a/include/coap3/libcoap.h b/include/coap3/libcoap.h
index f5e0e09..bf9ff53 100644
--- a/include/coap3/libcoap.h
+++ b/include/coap3/libcoap.h
@@ -26,10 +26,9 @@
  * The CONTIKI variable is within the Contiki-NG build environment! */
 
 #if defined(_WIN32)
+#include <ws2tcpip.h>
 #if !defined(__MINGW32__)
 #pragma comment(lib,"Ws2_32.lib")
-#endif /* !defined(__MINGW32__) */
-#include <ws2tcpip.h>
 #ifndef _SSIZE_T_DECLARED
 typedef SSIZE_T ssize_t;
 #define        _SSIZE_T_DECLARED
@@ -38,6 +37,7 @@ typedef SSIZE_T ssize_t;
 typedef USHORT in_port_t;
 #define        _IN_PORT_T_DECLARED
 #endif
+#endif /* !defined(__MINGW32__) */
 #elif !defined (CONTIKI) && !defined (WITH_LWIP)
 #include <netinet/in.h>
 #include <sys/socket.h>
diff --git a/src/coap_ws.c b/src/coap_ws.c
index b3392f9..3045af9 100644
--- a/src/coap_ws.c
+++ b/src/coap_ws.c
@@ -229,10 +229,10 @@ coap_ws_write(coap_session_t *session, const uint8_t *data, size_t datalen) {
     hdr_len += 2;
   } else {
     ws_header[1] = 127;
-    ws_header[2] = (datalen >> 56) & 0xff;
-    ws_header[3] = (datalen >> 48) & 0xff;
-    ws_header[4] = (datalen >> 40) & 0xff;
-    ws_header[5] = (datalen >> 32) & 0xff;
+    ws_header[2] = ((uint64_t)datalen >> 56) & 0xff;
+    ws_header[3] = ((uint64_t)datalen >> 48) & 0xff;
+    ws_header[4] = ((uint64_t)datalen >> 40) & 0xff;
+    ws_header[5] = ((uint64_t)datalen >> 32) & 0xff;
     ws_header[6] = (datalen >> 24) & 0xff;
     ws_header[7] = (datalen >> 16) & 0xff;
     ws_header[8] = (datalen >>  8) & 0xff;

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

32 bit MinGW support pushed to #1062. Please confirm that your tests are successful then I will merge this into the develop branch.

from libcoap.

MrHulu avatar MrHulu commented on September 27, 2024

32 bit MinGW support pushed to #1062. Please confirm that your tests are successful then I will merge this into the develop branch.

32-bit MinGW can now be built successfully! Thanks to the experts!

from libcoap.

mrdeep1 avatar mrdeep1 commented on September 27, 2024

Thanks for the feedback. I will get #1062 merged shortly. Closing this issue.

from libcoap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.