Sep 7

libcurl库的资料大全 不指定

ljh , 16:59 , 利剑之辉的快乐生活 , 评论(0) , 引用(0) , 阅读(1956) , Via 本站原创 | |

libcurl库

A.在windows环境下编译libcurl库

Download Microsoft Platform SDK
========================================================
    http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en
    Install it


Download Zlib Source
========================================================
    from http://www.zlib.net/
    http://www.zlib.net/zlib123.zip


Build Zlib
========================================================
    Use Visual C++ 6
    zlib123\projects\visualc6\zlib.dsw


Download Openssl Source
========================================================
    from http://www.openssl.org/source/
    http://www.openssl.org/source/openssl-0.9.8g.tar.gz


Build Openssl
========================================================
    maybe need to install active perl
    http://lccnc.skycn.com/down/ActivePerl-5.8.8.822-MSWin32-x86-280952.zip

    # run build shell
    cd openssl-***
    ms\32all.bat


Download Curl Source
========================================================
    from http://curl.haxx.se/
    http://curl.haxx.se/download/curl-7.18.1.zip


Build Curl
========================================================
    1. Pre Build
  
    a. create bat file for debug
    call "C:\Program Files\Microsoft Visual Studio\VC98\Bin\vcvars32.bat"
    set CFG=debug-dll-ssl-dll-zlib-dll
    set OPENSSL_PATH=D:\svn_work\MDS\USS\trunk\openssl-0.9.8g
    set ZLIB_PATH=D:\svn_work\MDS\USS\trunk\zlib123-dll
    nmake -f Makefile.vc6

    b. create bat file for release
    call "C:\Program Files\Microsoft Visual Studio\VC98\Bin\vcvars32.bat"
    set CFG=release-dll-ssl-dll-zlib-dll
    set OPENSSL_PATH=D:\svn_work\MDS\USS\trunk\openssl-0.9.8g
    set ZLIB_PATH=D:\svn_work\MDS\USS\trunk\zlib123
    nmake -f Makefile.vc6

    c. save shell code to bat file
    Save to : curl-***\lib\build.bat

    d. modify curl-***\lib\Makefile.vc6
    Find
        CFLAGS     = /I. /I../include /nologo /W3 /GX /DWIN32 /YX /FD /c /DBUILDING_LIBCURL
    set as
        CFLAGS     = /I. /I../include /nologo /W3 /GX /DWIN32 /YX /FD /c /DBUILDING_LIBCURL  /I"C:\Program Files\Microsoft Platform SDK\Include"

    e. copy zlib123\projects\visualc6\Win32_DLL_Release\zlib1.lib to curl-7.18.1\lib\zdll.lib


    2. Build
    cd curl-***\lib
    build.bat
  

在Windows下使用libcurl、curlpp
<!--[if !vml]--><!--[endif]-->

1. 下载libcurl、curlpp源代码

http://curl.haxx.se/

http://rrette.com/textpattern/index.php?s=cURLpp

例如下载

http://curl.haxx.se/download/curl-7.16.2.tar.bz2

http://rrette.com/files/curlpp/curlpp-0.7/curlpp-0.7.0.tar.gz

2. 下载zlib

http://www.zlib.net/

例如下载

http://www.zlib.net/zlib123-dll.zip

3. 编译OpenSSL

参考Windows下Openssl安装以及编程(Visual C++版)

4. 编译libcurl,以VS2005为例

将curl-7.16.2.tar.bz2解压到某目录,例如C:\curl,进入C:\curl\lib目录。

将zlib123-dll.zip解压到某目录,例如C:\zlib

设Openssl的目录为C:\openssl

进入Visual Studio 2005命令提示,进入C:\curl\lib

编译Debug版本。

set CFG=debug-dll-ssl-dll-zlib-dll

set OPENSSL_PATH=C:/openssl

set ZLIB_PATH=C:/zlib/include

nmake -f Makefile.vc8

其输出:libcurld_imp.lib, libcurld.dll

编译Release版本。

set CFG=release-dll-ssl-dll-zlib-dll

set OPENSSL_PATH=C:/openssl

set ZLIB_PATH=C:/zlib/include

nmake -f Makefile.vc8

其输出:libcurl_imp.lib, libcurl.dll

如果需要编译其他版本,可查看设定相应的CFG 参数即可。

5.编译curlpp

将curlpp-0.7.0.tar.gz解压到某目录,例如C:\curlpp\curlpp

set CFG=release

nmake -f Makefile.msvc

如果需要编译其他版本,可查看设定相应的CFG 参数即可。

需要注意的是可能需要对原文件进行一定的修改。

一种方案是:

修改Makefile.msvc中LIBCURL_PATH

修改dllfct.h关于CURLPPAPI的宏定义

#define CURLPPAPI 

6.测试

该程序是备份CUBlog程序的C++版,需要boost库

#include <iostream>
#include <string>
#include <queue>

#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>
#include <boost/tuple/tuple.hpp>

#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>

#pragma comment(lib,"libcurlpp.lib")
#pragma comment(lib,"libcurl_imp.lib")

using namespace std;

#define MAX_FILE_LENGTH 20000

class WriterMemoryClass
{
    public:
    // Helper Class for reading result from remote host
    WriterMemoryClass(){
        this->m_pBuffer = NULL;
        this->m_pBuffer = (char*) malloc(MAX_FILE_LENGTH * sizeof(char));
        this->m_Size = 0;
    }
    ~WriterMemoryClass() {
        if (this->m_pBuffer)
            free(this->m_pBuffer);
    }
    void* Realloc(void* ptr, size_t size) {
        if(ptr)
            return realloc(ptr, size);
        else
            return malloc(size);
    }
    // Callback must be declared static, otherwise it won't link...
    size_t WriteMemoryCallback(char* ptr, size_t size, size_t nmemb) {
        // Calculate the real size of the incoming buffer
        size_t realsize = size * nmemb;
        // (Re)Allocate memory for the buffer
        m_pBuffer = (char*) Realloc(m_pBuffer, m_Size + realsize);
        // Test if Buffer is initialized correctly & copy memory
        if (m_pBuffer == NULL) {
            realsize = 0;
        }
       
        memcpy(&(m_pBuffer[m_Size]), ptr, realsize);
        m_Size += realsize;
        // return the real size of the buffer...
        return realsize;
    }
   
    // Public member vars
    char* m_pBuffer;
    size_t m_Size;
};

int main(int argc,char * argv[])
{
    string list_base="http://blog.chinaunix.net/u/8780/article.php?frmid=0&page=";
    string art_base="http://blog.chinaunix.net/u/8780/showart.php?id=";
    boost::regex rexp("<a href=\"showart_([0-9]{6}).*?><font.*?><b>(.*?)</b></font></a>");
    boost::regex fnp("[/\\:*?\"<>]");
    typedef boost::tuple<string,string> element;
    queue<element> q;
    bool save=true;
    if(argc==1)
        save=false;
       
    try {
        cURLpp::Cleanup cleaner;
        cURLpp::Easy request;
        cURLpp::Easy handler;
       int i=0;
        bool cond=true;
        while(cond) {
            i++;
            cond=false;
            string list_url=list_base+boost::lexical_cast<string>(i);
            cerr<<list_url<<endl;
            // Get the content
            WriterMemoryClass mWriterChunk;
            // Set the writer callback t
 

 

内文分页: [1] [2] [3]
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]