ubuntu 8.04 + Eclipse 下安装测试 libcurl 全过程
啊。GOOGLE也用这个。测试过程如下:
1、 安装
很简单,用新立得安装 libcurl3,libcurl3-dbg,libcurl4-openssl-dev两个包及
其相关包。其实安装的是libcurl的7.18.0版本。现在最新的是7.19,哈,懒得编
译了。
2、设置
免,如果是在VC下,还得设置的,但LINUX由于优秀的目录结构,这个免了。
3、在eclipse中创建一个C或C++项目进行测试。
贴进去的测试代码如下
#include <iostream>
#include "curl/curl.h"
using namespace std;
int main(void) {
CURL *curl;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
CURLcode res;
res = curl_easy_setopt(curl, CURLOPT_PROXY, "Test-pxy08:8080");
res = curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
res = curl_easy_setopt(curl, CURLOPT_URL, " http://www.vckbase.com");
res = curl_easy_perform(curl);
if (CURLE_OK == res) {
char *ct;
/**//* ask for the content-type */
/**//* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
if ((CURLE_OK == res) && ct)
cout << "We received Content-Type:" << ct << endl;
}
/**//* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
然后进行编译,结果出现undefined reference错误,又研究了个把小时这个错误
的原因,结果还是不行。
后在网上看到一例子,用命令行编译
gcc -o twit curl_twitter.c -lcurl
试着做了一下,居然通过了。
晕,看来还得加入curl引用啊。
在Eclipse项目属性里找到 C/C++ Build-->Settings-->Tool Settings-->GCC C++
Linker-->Libraries,在右边添加 curl ,然后编译,成功了。
自此,终于可以用libcurl下载网页,然后用boost正则表达式进行分析了。