在cmake中设置curl库路径

时间:2014-11-02 21:28:09

标签: c++ curl path cmake libcurl

我下载了“curl library”以供第三方应用程序使用。当我运行包含的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".

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

感谢您的帮助..

编辑: 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)
   ...

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

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

3 个答案:

答案 0 :(得分:6)

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

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})

答案 1 :(得分:1)

通过pkgconfig

include(FindPkgConfig)
pkg_check_modules(CURL libcurl REQUIRED)
include_directories(
  SYSTEM ${CURL_INCLUDE_DIRS}
)
target_link_libraries(YOURTARGETNAME
  ${CURL_LIBRARIES}
)

答案 2 :(得分:0)

您应该首先使用以下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

然后安装可用的pkg

sudu yum install libcurl-devel.x86_64