__dimaz
Сообщений: 1
Оценки: 0
Присоединился: 2009-09-19 18:05:48.160000
|
Добрый день, столкнулся с проблемой установки библиотеки cURL на Билдер С++ , сделал все как тут показанно http://www.xakep.ru/magazine/xa/121/092/1.asp Линкер ругаеться : Build [C++ Warning] cplus.cpp(18): W8094 Incorrect use of #pragma comment( <type> [,"string"] ) [C++ Warning] cplus.cpp(104): W8053 'sleep(unsigned int)' is obsolete [C++ Warning] cplus.cpp(140): W8004 'cc' is assigned a value that is never used [C++ Warning] cplus.cpp(155): W8012 Comparing signed and unsigned values [C++ Warning] cplus.cpp(167): W8012 Comparing signed and unsigned values [Linker Error] Unresolved external '_curl_global_init' referenced from C:\QIP_RFILES\7100080_SUPPORT RICH-HOST\CPLUS\CPLUS.OBJ [Linker Error] Unresolved external '_curl_formadd' referenced from C:\QIP_RFILES\7100080_SUPPORT RICH-HOST\CPLUS\CPLUS.OBJ [Linker Error] Unresolved external '_curl_formfree' referenced from C:\QIP_RFILES\7100080_SUPPORT RICH-HOST\CPLUS\CPLUS.OBJ [Linker Error] Unresolved external '_curl_easy_init' referenced from C:\QIP_RFILES\7100080_SUPPORT RICH-HOST\CPLUS\CPLUS.OBJ [Linker Error] Unresolved external '_curl_easy_setopt' referenced from C:\QIP_RFILES\7100080_SUPPORT RICH-HOST\CPLUS\CPLUS.OBJ [Linker Error] Unresolved external '_curl_easy_perform' referenced from C:\QIP_RFILES\7100080_SUPPORT RICH-HOST\CPLUS\CPLUS.OBJ [Linker Error] Unresolved external '_curl_easy_cleanup' referenced from C:\QIP_RFILES\7100080_SUPPORT RICH-HOST\CPLUS\CPLUS.OBJ [Linker Error] Unresolved external '_curl_global_cleanup' referenced from C:\QIP_RFILES\7100080_SUPPORT RICH-HOST\CPLUS\CPLUS.OBJ Как мне решить эту проблему.Заранее спасибо. PS часть кода : /*
ac-service.info C++ w/CURL usage example
1. replace variable "ackey" with your own
2. replace variable "captchafile" with your own captcha filename
3. compile with g++ option -lcurl
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dos.h>
//#include <unistd.h>
#include <string>
#include <curl/curl.h>
//#pragma comment (lib, "Ws2_32.lib")
//#pragma comment (dll, "libcurl.dll")
//#pragma comment(lib, "libcurlppMD.lib")
//------
using namespace std;
string contents,tempstr;
string ackey="";
string captchafile="captcha.jpg";
size_t handle_data(void *ptr, size_t size, size_t nmemb, void *stream);
bool myCheckIn(string& HTML, int *pos, string str, bool reg);
int strpos(string& haystack, const char * needle);
string substr(string& str, int pos, int offset);
int main()
{
/*
HINSTANCE cl = NULL;
if( ( cl = LoadLibrary( "libcurl.dll" ) ) == NULL )
//\\ загружаем библиотеку
MessageBox(NULL, "I can't loadlibcurl","ERROR", 0);
//\\если нельзя загрузить
// FreeLibrary(cl);
*/
int captcha_id=0;
CURL *hCurl = NULL;
CURLcode cc;
char error_buffer[1024];
char tmp_char[256];
if (!hCurl)
{
cc = curl_global_init(CURL_GLOBAL_ALL);
hCurl = curl_easy_init();
}
if (hCurl)
{
char *url = "http://ac-service.info/in.php";
struct curl_httppost *post=NULL;
struct curl_httppost *last=NULL;
curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, handle_data);
curl_easy_setopt(hCurl, CURLOPT_URL, url);
curl_easy_setopt(hCurl, CURLOPT_ERRORBUFFER, &error_buffer);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "method", CURLFORM_COPYCONTENTS, "post", CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "key", CURLFORM_COPYCONTENTS, ackey.c_str(), CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "file", CURLFORM_FILE, captchafile.c_str(), CURLFORM_CONTENTTYPE, "image/jpeg", CURLFORM_END);
//setting form fields to handler
curl_easy_setopt(hCurl, CURLOPT_HTTPPOST, post);
//posting
curl_easy_perform(hCurl);
//cleaning
curl_formfree(post);
curl_easy_cleanup(hCurl);
curl_global_cleanup();
//checking for error
if (strpos(contents,"ERROR")!=-1)
{
printf("found error: %s\n",contents.c_str());
exit(1);
}
//getting id
tempstr=substr(contents,3,10);
captcha_id=atoi(tempstr.c_str());
printf("captcha id: %d\n",captcha_id);
contents="";
//creating new url
sprintf(tmp_char,"http://ac-service.info/res.php?key=%s&action=get&id=%d",ackey.c_str(),captcha_id);
//sleeping for 10-second periods and pinging anti-captcha
while (1)
{
printf("sleeping for 10 seconds....\n");
sleep(10);
printf("checking for captcha result...");
hCurl = curl_easy_init();
if (hCurl)
{
curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, handle_data);
curl_easy_setopt(hCurl, CURLOPT_URL, tmp_char);
curl_easy_setopt(hCurl, CURLOPT_ERRORBUFFER, &error_buffer);
curl_easy_perform(hCurl);
curl_easy_cleanup(hCurl);
curl_global_cleanup();
if (strpos(contents,"NOT_READY")!=-1)
{
printf("captcha is not ready yet\n");
}
if (strpos(contents,"ERROR")!=-1)
{
//found error
printf("error: %s\n",contents.c_str());
exit(1);
}
if (strpos(contents,"OK")!=-1)
{
//captcha is ready
tempstr=substr(contents,3,30);
printf("captcha result: %s\n",tempstr.c_str());
break;
}
contents="";
} else { printf("CURL error\n"); exit(1); }
}
} else printf("CURL error\n");
printf("done\n");
}
size_t handle_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
int numbytes = size*nmemb;
char lastchar = *((char *) ptr + numbytes - 1);
*((char *) ptr + numbytes - 1) = '\0';
contents.append((char *)ptr);
contents.append(1,lastchar);
*((char *) ptr + numbytes - 1) = lastchar;
return size*nmemb;
}
bool myCheckIn(string& HTML, int *pos, string str, bool reg)
{
if(HTML.size() < *pos + str.size()) return false;
for(int i = 0; i < str.size(); i++)
{
if(str<i> != HTML[i + *pos]) return false;
}
*pos += str.size() - 1;
return true;
}
int strpos(string& haystack, const char * needle)
{
int i;
string tmp;
tmp=needle;
for (i=0;i<haystack.size();i++)
{
if (myCheckIn(haystack, &i,tmp,true)) return (i-tmp.size()+1);
}
return -1;
}
string substr(string& str, int pos, int offset)
{
int i;
string res;
for (i=pos;i<(pos+offset);i++)
{
res += str<i>;
}
return res;
}
|