I am trying to use curl in a C++ application I am developing using Visual Studio 2017. I like the idea of using Nuget because it is a very clean way of implementing a library. I tried to follow the example below from the Microsoft forum, which led me to use the “rmt_curl” package (linked below). This, however, left VS unable to find “curl.h”.
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a5cf5caa-450e-425b-af5b-84f8e1c198f9/c-visual-studio-2015-how-to-include-nuget-package-in-my-project?forum=vcgeneral
rmt_curl nuget package: https://www.nuget.org/packages/rmt_curl/
So I switched to use the “curl” package, which fixed the header file, but resulted in “unresolved external symbol” for each of the curl functions.
curl nuget package: https://www.nuget.org/packages/curl/
Inspired by other comments and answers I added “libcurl.lib” to the project “Properties->Linker->Input->Additional Dependencies” list. This results in “cannot open file ‘libcurl.lib’”.
After trying about half of the “libcurl.lib files in the “packages\curl.7.30.0.2” folder, I finally found one that compiled. I added “$(SolutionDir)\packages\curl.7.30.0.2\build\native\lib\v110\Win32\$(Configuration)\dynamic” to the project “Properties->Linker->General->Additional Library Directories” field.
Now the problem is that when running it, “LIBCURL.dll is not found”. This made realize that earlier I liked against the dynamic version of the .lib file. This is not what I want. I want to statically link the library and not bother with a DLL.
Here is the sample code I am trying to run before I try this in my real application:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <curl/curl.h>
int main()
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
I looked in detail at each of these related questions and if the answer that I need is in there, I do not see it:
unresolved external symbol using curl NuGet
cURL with Visual Studio 2013
CURL Nuget visual studio 2013 unresolved external symbol __imp__curl_easy_init referenced in function _main()
Add curl library C++
This is the first time I am using Nuget with a C++ project, so it is very possible that I simply do not understand something simple.