Compilation errors with BoringSSL: openssl\x509.h(1335,1): error C2059: syntax error: '<parameter-list>' (minimal reproducible example included)
I'm trying to build a static version of libwebsockets 4.4.1 using
- A static build of BoringSSL 0.20250818.0 as the TLS lib
- MSVC 2022 x64 on Windows 11 64bit as the compiler
- CMake as the meta build system
A minimal reproducible example in the form of a PowerShell script that executes the whole build process, from downloading the sources to launching the actual build commands can be found at the end of this post.
Despite successfully building the BoringSSL library and filling in the proper CMake cache variables, I get the following compilation errors when building libwebsockets:
...\workdir7\boringssl-install\include\openssl\x509.h(1335,1): error C2059: syntax error: '<parameter-list>' [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-fds.c')
...\workdir7\boringssl-install\include\openssl\x509.h(1335,1): error C2143: syntax error: missing ')' before '(' [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-fds.c')
...\workdir7\boringssl-install\include\openssl\x509.h(1335,1): error C2059: syntax error: ')' [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-fds.c')
...\workdir7\boringssl-install\include\openssl\x509.h(1335,1): error C2143: syntax error: missing ')' before 'constant' [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-fds.c')
...\workdir7\boringssl-install\include\openssl\x509.h(1335,1): error C2091: function returns function [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-fds.c')
...\workdir7\boringssl-install\include\openssl\x509.h(1335,1): error C2143: syntax error: missing '{' before 'constant' [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-fds.c')
...\workdir7\boringssl-install\include\openssl\x509.h(1335,1): error C2059: syntax error: 'constant' [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-fds.c')
...\workdir7\boringssl-install\include\openssl\x509.h(1335,1): error C1003: error count exceeds 100; stopping compilation [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-fds.c')
...\workdir7\boringssl-install\include\openssl\base.h(293,29): error C2059: syntax error: '<parameter-list>' [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-file.c')
...\workdir7\boringssl-install\include\openssl\pkcs7.h(123,14): error C2059: syntax error: '<parameter-list>' [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-file.c')
...\workdir7\boringssl-install\include\openssl\x509.h(138,16): error C2059: syntax error: '<parameter-list>' [...\workdir7\libwebsockets-build\lib\websockets.vcxproj]
(compiling source file '../../libwebsockets-src/lib/plat/windows/windows-file.c')
Could you please advise on how to solve these issues?
Thank you for developing this cool minimal-dependency libwebsockets lib and, in advance, for having a look at this issue 🙂
PS: As mentioned above, the following PowerShell script contains the whole build process, from downloading the sources to launching the actual build commands if you'd like to reproduce the issue on your end (please make sure to have nasm, go, cmake 3.x and git on your machine).
# .\build_lws_with_bssl.ps1
# Prerequisite Tools Can Be Passed In As Command-Line Arguments ####################################
param (
[Parameter(Mandatory = $true)]
[string] $WorkDir, # Work directory, will be created then used for downloading and building the sources
[Parameter(Mandatory = $true)]
[string] $NasmExe, # The nasm.exe binary name if it's in your PATH. Otherwise, fill in the full path to the nasm.exe binary
[Parameter(Mandatory = $true)]
[string] $GoExe, # The go.exe binary name if it's in your PATH. Otherwise, fill in the full path to the go.exe binary
[Parameter(Mandatory = $true)]
[string] $CMakeExe, # The cmake.exe binary name if it's in your PATH. Otherwise, fill in the full path to the cmake.exe binary
[Parameter(Mandatory = $true)]
[string] $GitExe # The git.exe binary name if it's in your PATH. Otherwise, fill in the full path to the git.exe binary
)
if ($PSVersionTable.PSVersion -lt [version]"7.5") {
throw "This script requires PowerShell >= v7.5. Remove this test if you want to try on PowerShell 5"
}
if (Test-Path "$WorkDir") {
throw "WorkDir [$WorkDir] already exists. Either remove it, remove this check or specify a new WorkDir"
}
#$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
#$WorkDir = Join-Path "$scriptDir" "WorkDir"
New-Item -ItemType Directory -Path "$WorkDir"
$WorkDir = $WorkDir | Resolve-Path
Write-Host "WorkDir: $WorkDir"
# BoringSSL ########################################################################################
$bsslSrcDir = (Join-Path "$WorkDir" "boringssl-src") -replace "\\","/"
$bsslBuildDir = (Join-Path "$WorkDir" "boringssl-build") -replace "\\","/"
$bsslInstallDir = (Join-Path "$WorkDir" "boringssl-install") -replace "\\","/"
& "$GitExe" clone --depth 1 --branch "0.20250818.0" "https://boringssl.googlesource.com/boringssl" "$bsslSrcDir"
& "$CMakeExe" -G"Visual Studio 17 2022" -Ax64 `
"-S$bsslSrcDir" `
"-B$bsslBuildDir" `
"-DCMAKE_INSTALL_PREFIX=$bsslInstallDir" `
"-DCMAKE_BUILD_TYPE=Release" `
"-DCMAKE_ASM_NASM_COMPILER=$NasmExe" `
"-DGO_EXECUTABLE=$GoExe" `
"-DBUILD_TESTING=OFF"
& "$CMakeExe" --build "$bsslBuildDir" --config Release --target install
# LWS ##############################################################################################
$lwsSrcDir = (Join-Path "$WorkDir" "libwebsockets-src") -replace "\\","/"
$lwsBuildDir = (Join-Path "$WorkDir" "libwebsockets-build") -replace "\\","/"
$lwsInstallDir = (Join-Path "$WorkDir" "libwebsockets-install") -replace "\\","/"
& "$GitExe" clone --depth 1 --branch "v4.4.1" "https://github.com/warmcat/libwebsockets.git" "$lwsSrcDir"
& "$CMakeExe" -G"Visual Studio 17 2022" -Ax64 `
"-S$lwsSrcDir" `
"-B$lwsBuildDir" `
"-DCMAKE_INSTALL_PREFIX=$lwsInstallDir" `
"-DCMAKE_BUILD_TYPE=Release" `
"-DLWS_WITH_BORINGSSL=ON" `
"-DOPENSSL_ROOT_DIR=$bsslInstallDir" `
"-DOPENSSL_INCLUDE_DIRS=$bsslInstallDir/include" `
"-DOPENSSL_LIBRARIES=$bsslInstallDir/lib/ssl.lib;$bsslInstallDir/lib/crypto.lib" `
"-DLWS_WITH_MINIMAL_EXAMPLES=OFF" `
"-DBUILD_TESTING=OFF" `
"-DLWS_STATIC_PIC=ON" `
"-DLWS_WITHOUT_CLIENT=OFF" `
"-DLWS_WITHOUT_SERVER=OFF" `
"-DLWS_WITH_HTTP2=ON" `
"-DLWS_WITH_SECURE_STREAMS=ON" `
"-DLWS_WITH_SECURE_STREAMS_CPP=OFF" `
"-DLWS_WITH_STATIC=ON"
& "$CMakeExe" --build "$lwsBuildDir" --config Release --target install
So... 1) I build boringssl +lws in CI for Linux, there are no problems. 2) I google for 30s and find this https://github.com/curl/curl/issues/5669 from 2020, so this issue is not related to lws, it's an include ordering problem specific to windows. Read that issue for an alleged workaround.
Hi Andy! Thanks again for looking into this issue.
The workaround mentioned in https://github.com/curl/curl/issues/5669 which, in my understanding, has been implemented in https://github.com/curl/curl/pull/5857 seems to consist of undefining some wincrypt.h macros that conflict with BoringSSL.
After adapting it to libwebsockets 4.4.1 it seems to solve the problem indeed. Here is the patch:
diff --git a/lib/plat/windows/private-lib-plat-windows.h b/lib/plat/windows/private-lib-plat-windows.h
index ef9a8d1..bb8778a 100644
--- a/lib/plat/windows/private-lib-plat-windows.h
+++ b/lib/plat/windows/private-lib-plat-windows.h
@@ -70,6 +70,12 @@
#if defined(LWS_WITH_TLS)
#include <wincrypt.h>
+#if defined(LWS_WITH_BORINGSSL)
+ /* Undefine wincrypt.h symbols that conflict with BoringSSL */
+ #undef X509_NAME
+ #undef X509_EXTENSIONS
+ #undef PKCS7_SIGNER_INFO
+#endif
#endif
#if defined(LWS_HAVE_PTHREAD_H)
I have created a PR (#3456) to integrate it and hopefully help more users get up and running with libwebsockets and BoringSSL on Windows 🙂