I'm writing an OpenCV module to go with Kurento Media Server. I'm reading a file from an URL using lib curl.
The code I have is as follows:
#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);
Upon building it: I get the following warnings and the resultant package is not installed:
dpkg-shlibdeps: warning: symbol curl_easy_cleanup found in none of the libraries
dpkg-shlibdeps: warning: symbol curl_easy_perform found in none of the libraries
dpkg-shlibdeps: warning: symbol curl_easy_setopt found in none of the libraries
dpkg-shlibdeps: warning: symbol curl_easy_init found in none of the libraries
My guess is that there is a problem with linking the libraries in CMakeLists.txt
So how should I link these libraries?
Is target_link_libraries() the correct way? If so, what is the syntax?
Edit:
These are the ways I've tried so far.
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} )
At the main folder project CMakeLists.txt
where other requires are done, you need to add:
pkg_check_modules(CURL REQUIRED curl)
Then in folder src/server
you need to modify CMakeLists.txt file as follows:
generate_code (
MODELS ${CMAKE_CURRENT_SOURCE_DIR}/interface
SERVER_STUB_DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/implementation/objects
SERVER_IMPL_LIB_EXTRA_LIBRARIES ${CURL_LIBRARIES}
)