我正在编写一个与Kurento Media Server一起使用的OpenCV模块。
我正在使用lib curl从URL读取文件。

我的代码如下:

#include<curl/curl.h>

size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata)
{
    vector<uchar> *stream = (vector<uchar>*)userdata;
    size_t count = size * nmemb;
    stream->insert(stream->end(), ptr, ptr + count);
    return count;
}

Mat curlImg(const char *img_url, int timeout=10)
{
    vector<uchar> stream;
    CURL *curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, img_url);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    return imdecode(stream, -1);
}

Mat image = curlImg(link);

构建后:我收到以下警告,并且未安装生成的软件包:

dpkg-shlibdeps:警告:在所有库中均未找到符号curl_easy_cleanup
dpkg-shlibdeps:警告:在所有库中均未找到符号curl_easy_perform
dpkg-shlibdeps:警告:在所有库中均未找到符号curl_easy_setopt
dpkg-shlibdeps:警告:在所有库中均未找到符号curl_easy_init

我的猜测是链接CMakeLists.txt中的库存在问题

那么我应该如何链接这些库呢?
target_link_libraries()是否正确?如果是这样,语法是什么?

编辑:

这些是我到目前为止尝试过的方法。

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

2
target_link_libraries (curl)

3
SET(${CURL_LIBRARIES} )

最佳答案

在完成其他要求的主文件夹项目CMakeLists.txt中,您需要添加:

pkg_check_modules(CURL REQUIRED curl)

然后在src/server文件夹中,您需要修改CMakeLists.txt文件,如下所示:
generate_code (
   MODELS ${CMAKE_CURRENT_SOURCE_DIR}/interface
   SERVER_STUB_DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/implementation/objects
   SERVER_IMPL_LIB_EXTRA_LIBRARIES ${CURL_LIBRARIES}
)

07-26 04:31