[英]c++14 - How to enable HTTPs using standalone libcurl library in windows
問題: 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
源代碼/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]
謝謝@stranger,你的回答對我很有幫助,但不幸的是它不起作用,因為在新的 curl 版本中你現在需要設置CURL_USE_SCHANNEL
變量。 在添加 curl 之前添加以下行:
option(CURL_USE_SCHANNEL "Use windows default SSL libraries" ON)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.