I am using the curl-8.8.0 version. I have installed using vcpkg(2024.07.12) . I have built a library as static. When linking libcurl.lib to sample code unable to build the sample code.
Sample code:
#include <iostream>
#include "curlcurl.h"
using namespace std;
size_t WriteCallback(void *contents, size_t count, size_t size, void *data)
{
try
{
((std::string*)data)->append((char*)contents, count * size);
return count * size;
}
catch (...) {}
return 0;
}
int main(int argc, char* argv[])
{
struct curl_slist *headerlist = NULL;
static const char buf[] = "Expect:";
headerlist = curl_slist_append(headerlist, buf);
CURL *curl = curl_easy_init();
CURLcode res;
long code;
std::string response;
string url = "http://localhost:6000/e/cfg";
if (curl)
{
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
curl_easy_cleanup(curl);
curl_slist_free_all(headerlist);
curl_global_cleanup();
}
return 0;
}
I have linked following libraries:
ws2_32.lib
Normaliz.lib
Crypt32.lib
Wldap32.lib
libcurl.lib
libssl.lib
I have try to build the sample code. But it is not building.
Error:
1>------ Build started: Project: Curl_POC, Configuration: Release x64 ------
1>libcurl.lib(doh.c.obj) : error LNK2001: unresolved external symbol __acrt_iob_func
1>libcurl.lib(formdata.c.obj) : error LNK2001: unresolved external symbol __acrt_iob_func
1>libcurl.lib(setopt.c.obj) : error LNK2001: unresolved external symbol __acrt_iob_func
1>libcurl.lib(cookie.c.obj) : error LNK2001: unresolved external symbol __acrt_iob_func
1>libcurl.lib(url.c.obj) : error LNK2001: unresolved external symbol __acrt_iob_func
1>libcurl.lib(mprintf.c.obj) : error LNK2001: unresolved external symbol __acrt_iob_func
1>libcurl.lib(asyn-thread.c.obj) : error LNK2019: unresolved external symbol __stdio_common_vswprintf referenced in function _vswprintf_c_l
1>libcurl.lib(altsvc.c.obj) : error LNK2019: unresolved external symbol __stdio_common_vsscanf referenced in function _vsscanf_l
1>libcurl.lib(hsts.c.obj) : error LNK2001: unresolved external symbol __stdio_common_vsscanf
1>libcurl.lib(http_aws_sigv4.c.obj) : error LNK2001: unresolved external symbol __stdio_common_vsscanf
1>libcurl.lib(mprintf.c.obj) : error LNK2019: unresolved external symbol __stdio_common_vsprintf referenced in function snprintf
1>E:curl_upgradePOCCurl_POCx64ReleaseCurl_POC.exe : fatal error LNK1120: 4 unresolved externals
I am using Visual Studio 12 2013 for my sample code. How to resolve the above error?.
New contributor
Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.