diff --git a/CMakeLists.txt b/CMakeLists.txt index 11cf6528..c1c9872f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,12 +223,6 @@ elseif(WIN32) endif() endif() -if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") - include_directories(SYSTEM "/opt/homebrew/include") - endif() -endif() - # mediakit 以及各个 runtime 依赖 # mediakit and various runtime dependencies update_cached(MK_LINK_LIBRARIES "") @@ -441,7 +435,9 @@ endif() find_package(OpenSSL QUIET) if(OPENSSL_FOUND AND ENABLE_OPENSSL) message(STATUS "found library: ${OPENSSL_LIBRARIES}, ENABLE_OPENSSL defined") - include_directories(${OPENSSL_INCLUDE_DIR}) + # BEFORE: 保证 openssl 头文件与实际链接的 openssl 库来自同一套安装(优先于 homebrew 的 include), + # 否则会出现头文件一套、链接库另一套导致的编译错误/运行期不一致。 + include_directories(BEFORE SYSTEM ${OPENSSL_INCLUDE_DIR}) update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_OPENSSL) update_cached_list(MK_LINK_LIBRARIES ${OPENSSL_LIBRARIES}) if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS) @@ -545,6 +541,15 @@ endif() ############################################################################## +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") + # 此处仅作为兜底: 让 homebrew 安装的第三方库头文件也能被找到。 + # 必须放在所有 find_package 之后, 否则 homebrew 的头文件会覆盖 vcpkg/pkg-config 找到的同名库头文件, + # 导致头文件与实际链接的库版本不一致(例如 homebrew 的 openssl 头文件 vs vcpkg 的 openssl 库)。 + include_directories(SYSTEM "/opt/homebrew/include") + endif() +endif() + # for version.h include_directories(${CMAKE_CURRENT_BINARY_DIR}) diff --git a/webrtc/DtlsTransport.cpp b/webrtc/DtlsTransport.cpp index 2480ce65..7da73c99 100644 --- a/webrtc/DtlsTransport.cpp +++ b/webrtc/DtlsTransport.cpp @@ -244,7 +244,9 @@ namespace RTC } // Set certificate fields. - certName = X509_get_subject_name(certificate); + // OpenSSL 3.6+ 声明为 `const X509_NAME *X509_get_subject_name(const X509 *)`, + // 旧版本返回 `X509_NAME *`;用 const_cast 兼容两种签名(certificate 非 const,去 const 是安全的)。 + certName = const_cast(X509_get_subject_name(certificate)); if (!certName) {