不能在cmake中包含libcurl

问题描述 投票:0回答:1

我在 mac 上准备了一个项目,现在我继续在 windows 上开发。

我的项目有这样的结构:

  • 项目
    • 包括
      • HttpClient.h
    • 源代码
      • HttpClient.cpp
      • CMakeLists.txt
    • CMakeLists.txt
    • 主.cpp
    • curl-8.5.0
      • ....

我的基础 CMakeLists.txt 看起来像这样:

cmake_minimum_required(VERSION 3.22)

project(ReadPr)

# Add the src folder to the list of directories containing source files
add_subdirectory(src)

# Add the include folder to the list of directories containing header files
include_directories(include)

# Find the curl package
find_package(CURL REQUIRED)

# Add the executable and link it with the source files, curl library
add_executable(readPr main.cpp)

# Link the executable with the target in the src directory
target_link_libraries(readPr ReadPrSrc)

# Link the executable with the curl library
target_link_libraries(readPr ${CURL_LIBRARIES})

# Include the curl and jsoncpp headers
include_directories(${CURL_INCLUDE_DIRS})

但在我的标题中我找不到#include 。我很困惑为什么相同的配置在 mac 上有效,但在 Windows 上却不行。

我也尝试过进行此更改,但没有成功:

# Set the path to the libcurl root directory
set(CURL_ROOT "${CMAKE_SOURCE_DIR}/curl-8.5.0")

# Find the curl package
find_package(CURL REQUIRED)

有人可以给我建议吗。

c++ cmake libcurl
1个回答
0
投票

@Botje 感谢您的提示,我现在感觉很傻,我更改我的 cmake 现在直接从存储库下载库以避免此问题,为此我将导入更改为:

include(FetchContent)
FetchContent_Declare(curl
    URL https://curl.se/download/curl-8.5.0.tar.gz
    DOWNLOAD_EXTRACT_TIMESTAMP true
)
FetchContent_MakeAvailable(curl)
© www.soinside.com 2019 - 2024. All rights reserved.