error: too few arguments to function 'int mbedtls_pk_parse_keyfile'
Tools:
- Window 10 64-bit
- CMake 3.27
- MinGW-w64 GCC 11.2
- Mbed-TLS 3.6.1
Tested versions:
- IXWebSocket-11.4.5 (March 6, 2024)
- IXWebSocket-master
Full log:
cmake -G "MinGW Makefiles" --fresh -S . -B build -DCMAKE_INSTALL_PREFIX=E:/libs/IXWebSocket-11.4.5-prefix -DZLIB_LIBRARY=E:/lib/zlib-1.3.1-prefix/lib/libzlibstatic.a -DZLIB_INCLUDE_DIR=E:/libs/zlib-1.3.1-prefix/include -DMBEDTLS_LIBRARY=E:/libs/mbedtls-3.6.1-prefix/lib/libmbedtls.a -DMBEDTLS_INCLUDE_DIRS=E:/libs/mbedtls-3.6.1-prefix/include -DMBEDX509_LIBRARY=E:/libs/mbedtls-3.6.1-prefix/lib/libmbedx509.a -DMBEDCRYPTO_LIBRARY=E:/libs/mbedtls-3.6.1-prefix/lib/libmbedcrypto.a -DUSE_TLS=ON -DUSE_WS=ON
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Qt/Tools/mingw1120_64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw1120_64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- TLS configured to use mbedtls
-- Found MbedTLS: E:/libs/mbedtls-3.6.1-prefix/include
-- Found ZLIB: E:/lib/zlib-1.3.1-prefix/lib/libzlibstatic.a (found version "1.3.1")
-- Build spdlog: 1.8.0
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Build type: Release
-- Configuring done (12.6s)
-- Generating done (0.1s)
-- Build files have been written to: E:/libs/IXWebSocket-master/build
cmake --build build -j4
[ 2%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.obj
[ 4%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/stdout_sinks.cpp.obj
[ 8%] [ 8%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/color_sinks.cpp.obj
Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXBench.cpp.obj
[ 10%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXCancellationRequest.cpp.obj
[ 12%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXConnectionState.cpp.obj
[ 14%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXDNSLookup.cpp.obj
[ 16%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXExponentialBackoff.cpp.obj
[ 18%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/file_sinks.cpp.obj
[ 20%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXGetFreePort.cpp.obj
[ 22%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/async.cpp.obj
[ 24%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXGzipCodec.cpp.obj
[ 26%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/cfg.cpp.obj
[ 28%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXHttp.cpp.obj
[ 30%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXHttpClient.cpp.obj
[ 32%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXHttpServer.cpp.obj
[ 34%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/fmt.cpp.obj
[ 36%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXNetSystem.cpp.obj
[ 38%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSelectInterrupt.cpp.obj
[ 40%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSelectInterruptFactory.cpp.obj
[ 42%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSelectInterruptPipe.cpp.obj
[ 44%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSelectInterruptEvent.cpp.obj
[ 46%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSetThreadName.cpp.obj
[ 48%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocket.cpp.obj
[ 50%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketConnect.cpp.obj
[ 52%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketFactory.cpp.obj
[ 54%] Linking CXX static library libspdlog.a
[ 56%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketServer.cpp.obj
[ 58%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketTLSOptions.cpp.obj
[ 58%] Built target spdlog
[ 60%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXStrCaseCompare.cpp.obj
[ 62%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXUdpSocket.cpp.obj
[ 64%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXUrlParser.cpp.obj
[ 66%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXUuid.cpp.obj
[ 68%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXUserAgent.cpp.obj
[ 70%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocket.cpp.obj
[ 72%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketCloseConstants.cpp.obj
[ 74%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketHandshake.cpp.obj
[ 76%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketHttpHeaders.cpp.obj
[ 78%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketPerMessageDeflate.cpp.obj
[ 80%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp.obj
[ 82%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp.obj
[ 84%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketProxyServer.cpp.obj
[ 86%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketServer.cpp.obj
[ 88%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketTransport.cpp.obj
[ 90%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketMbedTLS.cpp.obj
E:\libs\IXWebSocket-master\ixwebsocket\IXSocketMbedTLS.cpp: In member function 'bool ix::SocketMbedTLS::init(const string&, bool, std::string&)':
E:\libs\IXWebSocket-master\ixwebsocket\IXSocketMbedTLS.cpp:146:41: error: too few arguments to function 'int mbedtls_pk_parse_keyfile(mbedtls_pk_context*, const char*, const char*, int (*)(void*, unsigned char*, size_t), void*)'
146 | if (mbedtls_pk_parse_keyfile(&_pkey, _tlsOptions.keyFile.c_str(), "") < 0)
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from E:/libs/mbedtls-3.6.1-prefix/include/mbedtls/ssl_ciphersuites.h:16,
from E:/libs/mbedtls-3.6.1-prefix/include/mbedtls/ssl.h:20,
from E:/libs/mbedtls-3.6.1-prefix/include/mbedtls/debug.h:15,
from E:\libs\IXWebSocket-master\ixwebsocket\IXSocketMbedTLS.h:13,
from E:\libs\IXWebSocket-master\ixwebsocket\IXSocketMbedTLS.cpp:12:
E:/libs/mbedtls-3.6.1-prefix/include/mbedtls/pk.h:1174:5: note: declared here
1174 | int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx,
| ^~~~~~~~~~~~~~~~~~~~~~~~
mingw32-make.exe[2]: *** [CMakeFiles\ixwebsocket.dir\build.make:616: CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketMbedTLS.cpp.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:117: CMakeFiles/ixwebsocket.dir/all] Error 2
mingw32-make.exe: *** [Makefile:135: all] Error 2
I tried IXWebSocket 11.4.5 with MBed-TLS 2.28.9:
[ 90%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketMbedTLS.cpp.obj
[ 92%] Linking CXX static library libixwebsocket.a
[ 92%] Built target ixwebsocket
mingw32-make.exe[2]: *** No rule to make target 'E:/lib/zlib-1.3.1-prefix/lib/libzlibstatic.a', needed by 'ws/ws.exe'. Stop.
mingw32-make.exe[2]: *** Waiting for unfinished jobs....
[ 94%] Building CXX object ws/CMakeFiles/ws.dir/__/third_party/msgpack11/msgpack11.cpp.obj
[ 96%] Building CXX object ws/CMakeFiles/ws.dir/__/third_party/cpp-linenoise/linenoise.cpp.obj
[ 98%] Building CXX object ws/CMakeFiles/ws.dir/ws.cpp.obj
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:170: ws/CMakeFiles/ws.dir/all] Error 2
mingw32-make.exe: *** [Makefile:135: all] Error 2
I try to ignore the error message above. I build a simple hello, world project:
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(background_color)
add_executable(app) # WIN32
target_include_directories(app PRIVATE E:/libs/glad-2.0.6/include)
target_include_directories(app PRIVATE E:/libs/IXWebSocket-11.4.5-prefix/include)
target_sources(app
PRIVATE
E:/libs/glad-2.0.6/src/glad.c
main.cpp
)
# This code copies the "SDL3.dll" file to the build directory
add_custom_command(TARGET app POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_RUNTIME_DLLS:app> $<TARGET_FILE_DIR:app>
)
find_package(SDL3)
target_link_directories(app PRIVATE E:/libs/IXWebSocket-11.4.5-prefix/lib)
target_link_directories(app PRIVATE E:/libs/mbedtls-2.28.9-prefix/lib)
target_link_directories(app PRIVATE E:/libs/zlib-1.3.1-prefix/lib)
target_link_libraries(app PRIVATE zlibstatic ixwebsocket mbedcrypto mbedx509 ws2_32 mbedtls SDL3::SDL3)
target_compile_definitions(app PRIVATE SDL_MAIN_USE_CALLBACKS)
target_link_options(app PRIVATE -static-libgcc -static-libstdc++)
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: E:/_Projects/SDL3/mingw/websockets/ixwebsocket-opengl21-sdl3-cpp/dist/win
[ 33%] Linking CXX executable app.exe
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.obj):IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x87): undefined reference to `deflate'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.obj):IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x36c): undefined reference to `deflateEnd'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.obj):IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x3ca): undefined reference to `deflateInit2_'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.obj):IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x5bf): undefined reference to `deflate'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.obj):IXWebSocketPerMessageDeflateCodec.cpp:(.text+0xa6c): undefined reference to `inflateEnd'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.obj):IXWebSocketPerMessageDeflateCodec.cpp:(.text+0xaa6): undefined reference to `inflateInit2_'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.obj):IXWebSocketPerMessageDeflateCodec.cpp:(.text+0xbf4): undefined reference to `inflate'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.obj):IXWebSocketPerMessageDeflateCodec.cpp:(.text+0xd42): undefined reference to `deflate'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXSocketMbedTLS.cpp.obj):IXSocketMbedTLS.cpp:(.text+0x841): undefined reference to `__imp_CertOpenStore'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXSocketMbedTLS.cpp.obj):IXSocketMbedTLS.cpp:(.text+0x854): undefined reference to `__imp_CertEnumCertificatesInStore'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXSocketMbedTLS.cpp.obj):IXSocketMbedTLS.cpp:(.text+0x8ab): undefined reference to `__imp_CertFreeCertificateContext'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXSocketMbedTLS.cpp.obj):IXSocketMbedTLS.cpp:(.text+0x8b6): undefined reference to `__imp_CertCloseStore'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXGzipCodec.cpp.obj):IXGzipCodec.cp:(.text+0x7d): undefined reference to `deflateInit2_'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXGzipCodec.cpp.obj):IXGzipCodec.cp:(.text+0xca): undefined reference to `deflate'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXGzipCodec.cpp.obj):IXGzipCodec.cp:(.text+0x100): undefined reference to `deflateEnd'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXGzipCodec.cpp.obj):IXGzipCodec.cp:(.text+0x17f): undefined reference to `inflateInit2_'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXGzipCodec.cpp.obj):IXGzipCodec.cp:(.text+0x1f5): undefined reference to `inflate'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXGzipCodec.cpp.obj):IXGzipCodec.cp:(.text+0x205): undefined reference to `inflateEnd'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXGzipCodec.cpp.obj):IXGzipCodec.cp:(.text+0x234): undefined reference to `inflateEnd'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(net_sockets.c.obj):net_sockets.c:(.text+0x38d): undefined reference to `__imp_bind'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(net_sockets.c.obj):net_sockets.c:(.text+0x3cd): undefined reference to `__imp_listen'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(net_sockets.c.obj):net_sockets.c:(.text+0x4c9): undefined reference to `__imp_getsockopt'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(net_sockets.c.obj):net_sockets.c:(.text+0x51a): undefined reference to `__imp_accept'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(net_sockets.c.obj):net_sockets.c:(.text+0x573): undefined reference to `__imp_recvfrom'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(net_sockets.c.obj):net_sockets.c:(.text+0x656): undefined reference to `__imp_getsockname'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(net_sockets.c.obj):net_sockets.c:(.text+0x6ed): undefined reference to `__imp_bind'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(net_sockets.c.obj):net_sockets.c:(.text+0xeb7): undefined reference to `__imp_shutdown'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_tls.c.obj):ssl_tls.c:(.text+0x280a): undefined reference to `mbedtls_dhm_calc_secret'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_tls.c.obj):ssl_tls.c:(.text+0x291b): undefined reference to `mbedtls_ecdh_calc_secret'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_tls.c.obj):ssl_tls.c:(.text+0x50e3): undefined reference to `mbedtls_dhm_init'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_tls.c.obj):ssl_tls.c:(.text+0x50f5): undefined reference to `mbedtls_ecdh_init'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_tls.c.obj):ssl_tls.c:(.text+0x7ecd): undefined reference to `mbedtls_dhm_free'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_tls.c.obj):ssl_tls.c:(.text+0x7edf): undefined reference to `mbedtls_ecdh_free'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_cli.c.obj):ssl_cli.c:(.text+0x41fa): undefined reference to `mbedtls_dhm_read_params'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_cli.c.obj):ssl_cli.c:(.text+0x448b): undefined reference to `mbedtls_ecdh_read_params'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_cli.c.obj):ssl_cli.c:(.text+0x4c2a): undefined reference to `mbedtls_ecdh_get_params'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_cli.c.obj):ssl_cli.c:(.text+0x5eb5): undefined reference to `mbedtls_dhm_make_public'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_cli.c.obj):ssl_cli.c:(.text+0x5fbb): undefined reference to `mbedtls_dhm_calc_secret'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_cli.c.obj):ssl_cli.c:(.text+0x60cc): undefined reference to `mbedtls_ecdh_make_public'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_cli.c.obj):ssl_cli.c:(.text+0x619b): undefined reference to `mbedtls_ecdh_calc_secret'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_cli.c.obj):ssl_cli.c:(.text+0x64af): undefined reference to `mbedtls_dhm_make_public'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_cli.c.obj):ssl_cli.c:(.text+0x655f): undefined reference to `mbedtls_ecdh_make_public'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x5670): undefined reference to `mbedtls_ecdh_get_params'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x5816): undefined reference to `mbedtls_dhm_set_group'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x58c5): undefined reference to `mbedtls_dhm_make_params'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x5b44): undefined reference to `mbedtls_ecdh_setup'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x5bf1): undefined reference to `mbedtls_ecdh_make_params'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x6551): undefined reference to `mbedtls_dhm_read_public'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x6e97): undefined reference to `mbedtls_dhm_calc_secret'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x6f76): undefined reference to `mbedtls_ecdh_read_public'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x7047): undefined reference to `mbedtls_ecdh_calc_secret'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a(ssl_srv.c.obj):ssl_srv.c:(.text+0x74ad): undefined reference to `mbedtls_ecdh_read_public'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [CMakeFiles\app.dir\build.make:117: app.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/app.dir/all] Error 2
mingw32-make: *** [Makefile:90: all] Error 2
I think it is related to this error when I build IXWebSockets where was failed to build libzlibstatic.a:
[ 16%] Built target spdlog
[ 92%] Built target ixwebsocket
mingw32-make.exe[2]: *** No rule to make target 'E:/lib/zlib-1.3.1-prefix/lib/libzlibstatic.a', needed by 'ws/ws.exe'. Stop.
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:170: ws/CMakeFiles/ws.dir/all] Error 2
mingw32-make.exe: *** [Makefile:135: all] Error 2
Building IXWebSocket 11.4.5 with MBed-TLS 2.28.9 was solved. The path to libzlibstatic.a was incorrect - lib must be changed to libs:
cmake -G "MinGW Makefiles" --fresh -S . -B dist -DCMAKE_INSTALL_PREFIX=E:/libs/IXWebSocket-11.4.5-prefix -DZLIB_LIBRARY=E:/libs/zlib-1.3.1-prefix/lib/libzlibstatic.a -DZLIB_INCLUDE_DIR=E:/libs/zlib-1.3.1-prefix/include -DMBEDTLS_LIBRARY=E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a -DMBEDTLS_INCLUDE_DIRS=E:/libs/mbedtls-2.28.9-prefix/include -DMBEDX509_LIBRARY=E:/libs/mbedtls-2.28.9-prefix/lib/libmbedx509.a -DMBEDCRYPTO_LIBRARY=E:/libs/mbedtls-2.28.9-prefix/lib/libmbedcrypto.a -DUSE_TLS=ON -DUSE_WS=ON -DUSE_ZLIB=ON
cmake --build dist -j4
Output:
[ 90%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketMbedTLS.cpp.obj
[ 92%] Linking CXX static library libixwebsocket.a
[ 92%] Built target ixwebsocket
[ 94%] Linking CXX executable ws.exe
[100%] Built target ws
cmake --install dist
Output:
-- Install configuration: "Release"
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXBase64.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXBench.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXCancellationRequest.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXConnectionState.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXDNSLookup.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXExponentialBackoff.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXGetFreePort.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXGzipCodec.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXHttp.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXHttpClient.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXHttpServer.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXNetSystem.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXProgressCallback.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSelectInterrupt.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSelectInterruptFactory.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSelectInterruptPipe.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSelectInterruptEvent.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSetThreadName.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSocket.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSocketConnect.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSocketFactory.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSocketServer.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSocketTLSOptions.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXStrCaseCompare.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXUdpSocket.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXUniquePtr.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXUrlParser.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXUuid.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXUtf8Validator.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXUserAgent.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocket.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketCloseConstants.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketCloseInfo.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketErrorInfo.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketHandshake.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketHandshakeKeyGen.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketHttpHeaders.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketInitResult.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketMessage.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketMessageType.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketOpenInfo.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketPerMessageDeflate.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketPerMessageDeflateCodec.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketPerMessageDeflateOptions.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketProxyServer.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketSendData.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketSendInfo.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketServer.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketTransport.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXWebSocketVersion.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/include/ixwebsocket/IXSocketMbedTLS.h
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/lib/cmake/ixwebsocket/ixwebsocket-config.cmake
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/lib/pkgconfig/ixwebsocket.pc
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/lib/cmake/ixwebsocket/ixwebsocket-targets.cmake
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/lib/cmake/ixwebsocket/ixwebsocket-targets-release.cmake
-- Installing: E:/libs/IXWebSocket-11.4.5-prefix/bin/ws.exe
The order of linking of libraries is very important. Now I have a view errors:
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXSocketMbedTLS.cpp.obj):IXSocketMbedTLS.cpp:(.text+0x841): undefined reference to `__imp_CertOpenStore'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXSocketMbedTLS.cpp.obj):IXSocketMbedTLS.cpp:(.text+0x854): undefined reference to `__imp_CertEnumCertificatesInStore'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXSocketMbedTLS.cpp.obj):IXSocketMbedTLS.cpp:(.text+0x8ab): undefined reference to `__imp_CertFreeCertificateContext'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libs/IXWebSocket-11.4.5-prefix/lib/libixwebsocket.a(IXSocketMbedTLS.cpp.obj):IXSocketMbedTLS.cpp:(.text+0x8b6): undefined reference to `__imp_CertCloseStore'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [CMakeFiles\app.dir\build.make:117: app.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/app.dir/all] Error 2
mingw32-make: *** [Makefile:90: all] Error 2
I tried to solve them by adding libcrypto.a library from OpenSSL 1.1 folder but it didn't help:
target_link_directories(app PRIVATE C:/Qt/Tools/OpenSSL-1.1.1j/Win_x64/bin/ssl_1.1/x86_64)
target_link_libraries(app PRIVATE ixwebsocket mbedx509 ws2_32 mbedtls mbedcrypto crypto zlibstatic wsock32 SDL3::SDL3)
Added. the crypt32 library solved the problem! I have received a message from the Glitch.com and Render.com free Node.js hostings!
target_link_directories(app PRIVATE E:/libs/IXWebSocket-11.4.5-prefix/lib)
target_link_directories(app PRIVATE E:/libs/mbedtls-2.28.9-prefix/lib)
target_link_directories(app PRIVATE E:/libs/zlib-1.3.1-prefix/lib)
# https://github.com/msys2/MINGW-packages/issues/4821#issuecomment-521690294
target_link_libraries(app PRIVATE ixwebsocket mbedx509 ws2_32 mbedtls mbedcrypto crypt32 zlibstatic wsock32 SDL3::SDL3)
P.S. So, MBed-TLS v2.28.9 must be used with IXWebSocket 11.4.5 but MBed-TLS v3.x.x have the mbedtls_pk_parse_keyfile function that requires 5 arguments (not 3)
error: no matching function for call to 'mbedtls_pk_parse_keyfile' requires 3 arguments, but 5 were provided
So, I had this error with the latest IXWebSocket-11.4.5 and the latest Mbed-TLS 3.6.1: too few arguments to function 'int mbedtls_pk_parse_keyfile' I solved it by using MBed-TLS v2.28.9 instead of MBed-TLS v3.x.x. I have tried MBed-TLS v3.0.0 too but IXWebSocket-11.4.5 has the same error. So, the number of arguments of mbedtls_pk_parse_keyfile was changed in MBed-TLS v3.0.0 but IXWebSocket-11.4.5 uses the old version of MBed-TLS v2.x.x.
Download MBed-TLS 2.28.9 like this:
git clone --depth 1 --branch v2.28.9 https://github.com/Mbed-TLS/mbedtls.git
Set the installation path and configure it:
cmake -G "MinGW Makefiles" --fresh -S . -B dist -DCMAKE_INSTALL_PREFIX=E:/libs/mbedtls-2.28.9-prefix
Build it:
cmake --build dist -j4
Install it:
cmake --install dist
Install zlib with the same way. I use zlib v1.3.1. Download and install IXWebSocket-11.4.5 with the configuration:
cmake -G "MinGW Makefiles" --fresh -S . -B dist -DCMAKE_INSTALL_PREFIX=E:/libs/IXWebSocket-11.4.5-prefix -DZLIB_INCLUDE_DIR=E:/libs/zlib-1.3.1-prefix/include -DZLIB_LIBRARY=E:/libs/zlib-1.3.1-prefix/lib/libzlibstatic.a -DMBEDTLS_LIBRARY=E:/libs/mbedtls-2.28.9-prefix/lib/libmbedtls.a -DMBEDTLS_INCLUDE_DIRS=E:/libs/mbedtls-2.28.9-prefix/include -DMBEDX509_LIBRARY=E:/libs/mbedtls-2.28.9-prefix/lib/libmbedx509.a -DMBEDCRYPTO_LIBRARY=E:/libs/mbedtls-2.28.9-prefix/lib/libmbedcrypto.a -DUSE_TLS=ON -DUSE_WS=ON -DUSE_ZLIB=ON
cmake --build dist -j4
cmake --install dist
Use the following CMakeLists.txt in your projects:
# mkdir dist\win
# cd dist
# cmake -G "MinGW Makefiles" --fresh -S .. -B ..\dist\win
cmake_minimum_required(VERSION 3.20)
# cd win
# mingw32-make
project(ixwebsocket_example)
add_executable(app) # WIN32
target_include_directories(app PRIVATE E:/libs/IXWebSocket-11.4.5-prefix/include)
target_sources(app
PRIVATE
main.cpp
)
find_package(SDL3)
target_link_directories(app PRIVATE E:/libs/IXWebSocket-11.4.5-prefix/lib)
target_link_directories(app PRIVATE E:/libs/mbedtls-2.28.9-prefix/lib)
target_link_directories(app PRIVATE E:/libs/zlib-1.3.1-prefix/lib)
target_link_libraries(app PRIVATE ixwebsocket mbedx509 ws2_32 mbedtls mbedcrypto crypt32 zlibstatic wsock32)
target_link_options(app PRIVATE -static-libgcc -static-libstdc++)
If you use SDL3 for a window and OpenGL:
# mkdir dist\win
# cd dist
# cmake -G "MinGW Makefiles" --fresh -S .. -B ..\dist\win -DSDL3_DIR=E:\libs\sdl3-desktop-prefix\lib\cmake\SDL3
cmake_minimum_required(VERSION 3.20)
# cd win
# mingw32-make
cmake_minimum_required(VERSION 3.20)
project(ixwebsocket_example)
add_executable(app) # WIN32
target_include_directories(app PRIVATE E:/libs/glad-2.0.6/include)
target_include_directories(app PRIVATE E:/libs/IXWebSocket-11.4.5-prefix/include)
target_sources(app
PRIVATE
E:/libs/glad-2.0.6/src/glad.c
main.cpp
)
# This code copies the "SDL3.dll" file to the build directory
add_custom_command(TARGET app POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_RUNTIME_DLLS:app> $<TARGET_FILE_DIR:app>
)
find_package(SDL3)
target_link_directories(app PRIVATE E:/libs/IXWebSocket-11.4.5-prefix/lib)
target_link_directories(app PRIVATE E:/libs/mbedtls-2.28.9-prefix/lib)
target_link_directories(app PRIVATE E:/libs/zlib-1.3.1-prefix/lib)
# https://github.com/msys2/MINGW-packages/issues/4821#issuecomment-521690294
target_link_libraries(app PRIVATE ixwebsocket mbedx509 ws2_32 mbedtls mbedcrypto crypt32 zlibstatic wsock32 SDL3::SDL3)
target_compile_definitions(app PRIVATE SDL_MAIN_USE_CALLBACKS)
target_link_options(app PRIVATE -static-libgcc -static-libstdc++)
This is my step by step guide to install SDL3 on Windows but it can be useful for MacOS too if you need a window Setting up SDL3 for Windows using CMake and MinGW-w64 You can draw GUI using ImGUI and SDL3: Building ImGUI statically and setting up it to the CMake project
Server:
app.js
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', (ws) => {
console.log('Client connected');
ws.on('message', (message) => {
console.log('Received message:', message);
// Process the received message and send a response if needed
});
ws.on('close',
() => {
console.log('Client disconnected');
});
});
Client:
main.cpp
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <glad/glad.h>
#include <ixwebsocket/IXNetSystem.h>
#include <ixwebsocket/IXWebSocket.h>
#include <ixwebsocket/IXUserAgent.h>
#include <iostream>
// Our websocket object
ix::WebSocket webSocket;
struct AppContext
{
SDL_Window *window;
SDL_GLContext glContext;
SDL_AppResult appQuit = SDL_APP_CONTINUE;
};
SDL_AppResult SDL_Fail()
{
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Error %s", SDL_GetError());
return SDL_APP_FAILURE;
}
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{
// Init the library
if (!SDL_Init(SDL_INIT_VIDEO))
{
return SDL_Fail();
}
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); // Enable MULTISAMPLE
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2); // can be 2, 4, 8 or 16
// Create a window
SDL_Window *window = SDL_CreateWindow("SDL3, OpenGL 2.1, C++", 350, 350,
SDL_WINDOW_OPENGL); // | SDL_WINDOW_RESIZABLE
if (!window)
{
return SDL_Fail();
}
SDL_GLContext glContext = SDL_GL_CreateContext(window);
if (!glContext)
{
return SDL_Fail();
}
if (!gladLoadGL())
{
std::cout << "Failed to load OpenGL functions" << std::endl;
return SDL_APP_FAILURE;
}
glClearColor(0.2f, 0.3f, 0.5f, 1.f);
// Required on Windows
ix::initNetSystem();
// std::string url("wss://echo.websocket.org");
// std::string url("ws://localhost:3000");
// std::string url("wss://chat-sdl3-wasm-cpp.onrender.com");
std::string url("wss://testing-websockets-using-emscripten-sdl3-and-opengl-es-20.glitch.me");
webSocket.setUrl(url);
std::cout << "Connecting to " << url << "..." << std::endl;
// Setup a callback to be fired (in a background thread, watch out for race conditions !)
// when a message or an event (open, close, error) is received
webSocket.setOnMessageCallback([](const ix::WebSocketMessagePtr& msg)
{
if (msg->type == ix::WebSocketMessageType::Message)
{
std::cout << "received message: " << msg->str << std::endl;
std::cout << "> " << std::flush;
}
else if (msg->type == ix::WebSocketMessageType::Open)
{
std::cout << "Connection established" << std::endl;
std::cout << "> " << std::flush;
}
else if (msg->type == ix::WebSocketMessageType::Error)
{
// Maybe SSL is not configured properly
std::cout << "Connection error: " << msg->errorInfo.reason << std::endl;
// std::cout << "> " << std::flush;
}
}
);
// Now that our callback is setup, we can start our background thread and receive messages
webSocket.start();
// Send a message to the server (default to TEXT mode)
webSocket.send("hello world");
// Display a prompt
std::cout << "> " << std::flush;
std::string text;
// Read text from the console and send messages in text mode.
// Exit with Ctrl-D on Unix or Ctrl-Z on Windows.
// while (std::getline(std::cin, text))
// {
// webSocket.send(text);
// std::cout << "> " << std::flush;
// }
SDL_ShowWindow(window);
// Set up the application data
*appstate = new AppContext {
window,
glContext,
};
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
auto *app = (AppContext *)appstate;
switch (event->type)
{
case SDL_EVENT_QUIT:
{
app->appQuit = SDL_APP_SUCCESS;
break;
}
default:
{
break;
}
}
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppIterate(void *appstate)
{
auto *app = (AppContext *)appstate;
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(app->window);
return app->appQuit;
}
void SDL_AppQuit(void *appstate, SDL_AppResult result)
{
auto *app = (AppContext *)appstate;
if (app)
{
SDL_GL_DestroyContext(app->glContext);
SDL_DestroyWindow(app->window);
delete app;
}
SDL_Quit();
}
Nice, thanks for sharing.
There should be an mbedtls version detection blob somewhere, as the API changed in 3.xxx.
cf c27f5a94bd507ada6f633f23bede13bcd6cf8842