c++ - c++14 - 如何在 Windows 中使用独立的 libcurl 库启用 HTTPs
问题描述
问题: Libcurl 在 windows 上作为独立库工作,但不支持 https 协议,如何启用它?当我测试或使用我的 CurlClient 时,它工作正常。当我尝试向 https 站点发送请求时,我得到 curl 响应代码 1,这意味着 https 是不受支持的协议。
我构建 curl 时的 cmake 日志:
-- curl version=[7.69.0-DEV]
CMake Warning at lib/curl/CMake/Macros.cmake:86 (message):
Found no *nroff program
Call Stack (most recent call first):
lib/curl/CMakeLists.txt:215 (curl_nroff_check)
-- Could NOT find LibSSH2 (missing: LIBSSH2_LIBRARY) (found version "1.8.2")
-- Enabled features: IPv6 AsynchDNS NTLM
-- Enabled protocols: DICT FILE FTP GOPHER HTTP IMAP LDAP POP3 RTSP SMB SMTP TELNET TFTP
-- Enabled SSL backends:
我的项目结构:
CMakeLists.txt
/lib
/curl
/googletest
CMakeLists.txt
/src
/include
CurlClient.h
CurlClient.cc
CMakeLists.txt
/test
CurlClientTest.cc
main.cc
CMakeLists.txt
src/CMakeLists.txt:
cmake_minimum_required(VERSION 3.10.2)
project(simple_curl_cpp)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_subdirectory(src)
add_subdirectory(lib)
add_subdirectory(test)
库/CMakeLists.txt:
cmake_minimum_required(VERSION 3.10.2)
message(STATUS "Not using system Curl, using built-in curl project instead.")
option(BUILD_TESTING "Set to ON to build cURL tests." OFF)
option(BUILD_CURL_EXE "Set to ON to build cURL executable." OFF)
add_subdirectory(curl)
set(gtest_force_shared_crt TRUE CACHE INTERNAL "")
set(BUILD_GMOCK TRUE CACHE INTERNAL "")
set(INSTALL_GTEST FALSE)
set(gmock_build_tests FALSE CACHE INTERNAL "")
add_subdirectory(googletest)
测试/CMakeLists.txt:
cmake_minimum_required(VERSION 3.10.2)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(SOURCES
CurlClientTest.cc
../src/CurlClient.cc
)
set(HEADERS
../src/include/CurlClient.h
)
# googletest
enable_testing()
add_executable(simple_curl_cpp_test "main.cc" ${SOURCES} ${HEADERS})
target_link_libraries(simple_curl_cpp_test libcurl gtest)
add_test(
NAME simple_curl_cpp_test
COMMAND simple_curl_cpp_test
)
Strager给出的答案:
在 lib/CMakeLists.txt 之前输入add_subdirectory(curl)
:
option(CMAKE_USE_WINSSL "Set to ON to use WINSSL for windows." ON)
解决方案
在配置时尝试设置CMAKE_USE_WINSSL
CMake 变量:
PS> "C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_USE_WINSSL=ON ..
-- Building for: Visual Studio 16 2019
[snip]
-- Enabled features: SSL IPv6 AsynchDNS SSPI SPNEGO Kerberos NTLM
-- Enabled protocols: DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP
-- Enabled SSL backends: WinSSL
[snip]
-- Configuring done
[snip]
推荐阅读
- mysql - 将 MySQL 表数据实时提供给 ElasticSearch 的最佳方式是什么?
- c# - 字符串和串口输入的比较总是假的
- javascript - 搜索域:odoo 中的多个条件
- javascript - 使用通用导航菜单浏览多个页面时出错
- javascript - 为什么带有 React 框架的 Office.js 在带有普通 Javascript 的 Office.js 工作时会破坏端点数据
- java - 我可以在 x32 位环境中执行 java 的 Long 数据类型吗?
- prometheus - 5 分钟 CPU 负载平均规则
- javascript - Wait for firebase.auth initialization before reading another function
- ruby-on-rails - 将带有 AM/PM 的 12 小时时间字符串转换为 24 小时时间
- javascript - 在 javascript 中创建异步单例