Home > Back-end >  Based on VS2010 development environment, new construction using curl, json static library compiled t
Based on VS2010 development environment, new construction using curl, json static library compiled t

Time:09-17

Recently want to try to use c + + API interface link, but after the new construction, the import libraries how to also cannot successfully imported, below a specific operation process, hope to get some bosses,
1, building projects, and relevant configuration section:
First built an empty project:


The related. H. c file to join engineering:

For related configuration directory:




Attached my test code:

 
# include & lt; The curl. H>
# include & lt; Iostream>

# pragma comment (lib, "libcurl_a. Lib")
using namespace std;

/* *
* once the curl to receive data, will call the callback function
* buffer: data buffer pointer
* size: debugging stage is always found to 1
* nmemb: the memory block) on behalf of the accept the length of the memory block
* userp: user-defined parameters of a
*/
Size_t write_data (void * buffer, size_t size, size_t nmemb, void * userp)
{
Static int current_index=0;

cout <"Current" & lt; cout cout <"-- -- -- -- -- -- -- -- -- -- -- -- -- -- --" & lt;
Userp int temp=* (int *);//here for user-defined parameter
Return nmemb;
}

Int curl_test_h (void)
{
Curl_global_init (CURL_GLOBAL_ALL);//the first global initialization CURL
The CURL CURL *=curl_easy_init ();//handle to initialize the CURL

If (NULL==curl)
{
Printf (" (the curl is NULL! \r\n");
return 0;
}

Int my_param=1;//a custom user parameter

//set the target URL
Curl_easy_setopt (curl, CURLOPT_URL, "http://www.baidu.com");
//set to receive a callback function to be called by the HTTP server data
Curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION write_data);
//set custom parameters (the fourth parameter of the callback function)
Curl_easy_setopt (curl, CURLOPT_WRITEDATA, & amp; My_param);
To perform a URL request//
CURLcode res=curl_easy_perform (curl);
//clean up
Curl_easy_cleanup (curl);

return 0;
}

Void main ()
{
Printf (" hello world!" );
}

Error:
1> Test_C + + _eD_API3. Obj: error LNK2001: cannot resolve the external symbol of __imp__curl_easy_cleanup
1> Test_C + + _eD_API3. Obj: error LNK2001: cannot resolve the external symbol of __imp__curl_easy_perform
1> Test_C + + _eD_API3. Obj: error LNK2001: cannot resolve the external symbol of __imp__curl_easy_setopt
1> Test_C + + _eD_API3. Obj: error LNK2001: cannot resolve the external symbol of __imp__curl_easy_init
1> Test_C + + _eD_API3. Obj: error LNK2001: cannot resolve the external symbol of __imp__curl_global_init
1> D: \ documents \ visual studio 2010 \ Projects \ test_C + + _eD_API4 \ Debug \ test_C + + _eD_API4 exe: fatal error LNK1120: five cannot resolve the external command
1>
1> Generate failure,

(obviously is not import, but the problem is where? [beyond love. JPG])

2, enclosed I get libcurl_a. Lib and json.
the process of the libThe curl of the static library reference the greatly:
https://blog.csdn.net/cym1990/article/details/79851039
Json static library for reference methods:
https://www.cnblogs.com/zhangfengfly/p/7225926.html

CodePudding user response:

New report, meet you,
Their top down,
  • Related