C++ 在 cmake 中设置 curl 库路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26704629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:40:30  来源:igfitidea点击:

Setting up curl library path in cmake

c++curlpathcmakelibcurl

提问by nikk

I downloaded "curl library" for use with a third party application. When I run the included cmake file, I get the following error. Please help me. I appreciate it:

我下载了用于第三方应用程序的“curl 库”。当我运行包含的 cmake 文件时,出现以下错误。请帮我。我很感激:

> The C compiler identification is MSVC 18.0.30501.0
    >     The CXX compiler identification is MSVC 18.0.30501.0
    >     Check for working C compiler using: Visual Studio 12 2013
    >     Check for working C compiler using: Visual Studio 12 2013 -- works
    >     Detecting C compiler ABI info
    >     Detecting C compiler ABI info - done
    >     Check for working CXX compiler using: Visual Studio 12 2013
    >     Check for working CXX compiler using: Visual Studio 12 2013 -- works
    >     Detecting CXX compiler ABI info
    >     Detecting CXX compiler ABI info - done
    >     Could NOT find CURL (missing:  CURL_LIBRARY) (found version "7.38.0")
    >     CMake Error at CMakeLists.txt:49 (MESSAGE):
    >       Could not find the CURL library and development files.  
    >     
    >     Configuring incomplete, errors occurred!
    >     See also "C:/BUILD/CMakeFiles/CMakeOutput.log".

I set environment variable for "CURL_LIBRARY" in Windows to point to the location of the installation of library files for curl, but cmake can't still find it even though it indicates that version 7.38.0 was detected on my system.

我在 Windows 中为“CURL_LIBRARY”设置了环境变量以指向 curl 的库文件的安装位置,但是即使它表明在我的系统上检测到 7.38.0 版本,cmake 仍然找不到它。

Thanks for the help..

谢谢您的帮助..

EDIT: cMakeLists.txt file

编辑:cMakeLists.txt 文件

  ...
# Look for required libraries
SET(requiredlibs)

FIND_PACKAGE(CURL)
IF(CURL_FOUND)
  INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
  SET(requiredlibs ${requiredlibs} ${CURL_LIBRARIES} )
ELSE(CURL_FOUND)
  MESSAGE(FATAL_ERROR "Could not find the CURL library and development files.")
ENDIF(CURL_FOUND)
   ...

I set the include and lib dirs in Windows Environment Variable, but no change.

我在 Windows 环境变量中设置了 include 和 lib 目录,但没有改变。

EDIT: this is complete project file: cmake project.

编辑:这是完整的项目文件:cmake project

回答by miradham

I faced same problem and this SO question was one of top during my search. So I am giving solution that I found. Following cmake worked for me to use libcurl include in my code. Hope it will be usefull for someone.

我遇到了同样的问题,这个问题是我搜索过程中最重要的问题之一。所以我给出了我找到的解决方案。以下 cmake 为我工作,在我的代码中使用 libcurl 包含。希望它对某人有用。

set(CURL_LIBRARY "-lcurl") 
find_package(CURL REQUIRED) 
add_executable (curl-demo convert.cpp)
include_directories(${CURL_INCLUDE_DIR})
target_link_libraries(curl-demo ${CURL_LIBRARIES})

回答by Simon Zhang

You should install the libcurl-dev pkg with the following cmd first:

您应该首先使用以下 cmd 安装 libcurl-dev pkg:

$ yum search libcurl

Loading mirror speeds from cached hostfile
============================= N/S Matched: libcurl =============================
libcurl-devel.i686 : Files needed for building applications with libcurl
libcurl-devel.x86_64 : Files needed for building applications with libcurl
curlftpfs.x86_64 : CurlFtpFS is a filesystem for accessing FTP hosts based on
                 : FUSE and libcurl
curlpp.i686 : A C++ wrapper for libcURL
curlpp.x86_64 : A C++ wrapper for libcURL
libcurl.i686 : A library for getting files from web servers
libcurl.x86_64 : A library for getting files from web servers
perl-WWW-Curl.x86_64 : Perl extension interface for libcurl
python-pycurl.x86_64 : A Python interface to libcurl
rubygem-curb.x86_64 : Ruby libcurl bindings

then install the available pkg

然后安装可用的 pkg

sudu yum install libcurl-devel.x86_64