webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and HTML5 in the frontend, all in a lightweight portable lib.
https://webui.me
MIT License
2.36k stars 144 forks source link

Build failed using WEBUI_USE_TLS option using windows mingw #344

Closed mikaeser closed 2 months ago

mikaeser commented 3 months ago

Using WEBUI_USE_TLS=1 and corresponding paths results in type definition conflict with OpenSSL Inserting

    #ifndef WIN32_LEAN_AND_MEAN
        #define WIN32_LEAN_AND_MEAN
    #endif

just above the windows header include fixes the issue.

However I cannot link the built libwebui-2-secure-static.a library to my own c++ library with having linking errors with all the SSL functions. Without WEBUI_USE_TLS option, everything works fine.

AlbertShown commented 3 months ago

just above the windows header include fixes the issue

Got it, Thank you for the report. Can you please create a PR to fix this?

AlbertShown commented 3 months ago

to my own c++ library with having linking errors with all the SSL functions

You can share the logs if you want, we may find a solution, or maybe WEBUI_USE_TLS part can be improved.

mikaeser commented 3 months ago

Building a c++ test project with cmake ...

// Folder structure
// 
// CMakeLists.txt
// main.cpp
// libwebui-2-secure-static.a
// include
//  |- webui.h
//  |- webui.hpp

cmake_minimum_required(VERSION 3.26)

project(webui)
add_library(webui STATIC IMPORTED)
set_target_properties(webui PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/libwebui-2-secure-static.a")
target_include_directories(webui INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include")
target_link_libraries(webui INTERFACE ws2_32)

project(my_test)
add_executable(main main.cpp)
target_link_libraries(main webui)

results in ...

[main] Building folder: test 
[build] Starting build
...
[build] [ 50%] Linking CXX executable main.exe
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/.../git/test/libwebui-2-secure-static.a(webui.o):webui.c:(.text+0x1675): undefined reference to `OPENSSL_add_all_algorithms_noconf'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/.../git/test/libwebui-2-secure-static.a(webui.o):webui.c:(.text+0x167a): undefined reference to `SSL_library_init'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/.../git/test/libwebui-2-secure-static.a(webui.o):webui.c:(.text+0x167f): undefined reference to `TLS_client_method'
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/.../git/test/libwebui-2-secure-static.a(webui.o):webui.c:(.text+0x1687): undefined reference to `SSL_CTX_new'
...
...

Is this my fault or did something go wrong with WEBUI_USE_TLS option?

AlbertShown commented 3 months ago

I guess you need to modify your CMakeLists.txt to find and link the OpenSSL library first before webui.

cmake_minimum_required(VERSION 3.26)
project(webui)
find_package(OpenSSL REQUIRED)
...
target_link_libraries(main webui ws2_32 OpenSSL::SSL OpenSSL::Crypto)

However, this issue is related to Cmake and OpenSSL, webui works fine.

mikaeser commented 3 months ago

Manually linking to OpenSSL works. To link the OpenSSL library from mingw64 to WebUI I had to build it and set the TLS paths accordingly (not using the curl).

AlbertShown commented 2 months ago

Good, so issue is solved I guess?

mikaeser commented 2 months ago

Yes, thank you.