mingw编译器window下使用curl

tar -zxvf zlib-1.2.8.tar.gz 
cd zlib-1.2.8
cp ./win32/Makefile.gcc ./Makefile
mingw32-make
cd ..

tar -zxvf openssl-0.9.8zc.tar.gz
cd openssl-0.9.8zc
./config
修改Makefile去掉CFLAG参数中的-mno-cygwin选项
make
cd ..

tar -zxvf libssh2-1.6.0.tar.gz
cd libssh2-1.6.0/win32
mingw32-make lib -f GNUmakefile
cd ../../

tar -zxvf curl-7.47.1.tar.gz
cd curl-7.47.1/lib
#修改该木下的Makefile.m32文件:
#OPENSSL_PATH = ../../openssl-0.9.8zc
#LIBSSH2_PATH = ../../libssh2-1.6.0
mingw32-make -f Makefile.m32
cd ../../

测试例程test.c:
#include <stdio.h>  
#include <stdlib.h>  
#include <curl/curl.h>

size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);

int main(int argc,char *argv[])  
{  
    CURL *curl;  
    CURLcode res;  

    FILE* fp;
    if(argc != 3)  
    {  
        printf("cmd url file\n");  
        return -1;  
    }  

    do
    {
        //curl_global_init(CURL_GLOBAL_WIN32);//CURL_GLOBAL_ALL
        res = curl_global_init(CURL_GLOBAL_ALL);
        if(res != CURLE_OK)
        {
            printf("curl初始化失败");
            break;
        }
        fp = fopen(argv[2],"ab+");
        if(!fp)
        {
            printf("打开或创建文件失败");
            return -1;
        }

        // 初始化curl  
        curl = curl_easy_init();  

        if(curl != NULL)  
        {  
            // 设置目标url  
            curl_easy_setopt(curl,CURLOPT_URL,argv[1]);  
            //curl_easy_setopt(curl,CURLOPT_URL,"http://www.baidu.com/");

            //注册回调函数
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);

            //设置回调函数自定义参数
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);

            // 输出header头部信息  
            //curl_easy_setopt(curl,CURLOPT_HEADER,1);  

            // 连接到远程主机,执行操作,并接收数据。 
            res = curl_easy_perform(curl);  

            // 执行回收资源  
            curl_easy_cleanup(curl);  
        }else
        {
            printf("curl初始化失败\n");
        }
    }while(0);
    //保存内容
    fclose(fp);
    curl_global_cleanup();
    return 0;     
}

size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
    size_t total;
    FILE* fp = (FILE*)userp;
    total = fwrite(buffer,size,nmemb,fp);
    return total;
}

Makefile文件:
all:test

%:%.c
    gcc $^ -L lib -lcurl -lwldap32 -lws2_32 -DCURL_STATICLIB -I include -o $@

说明:lib为curl编译后库文件目录,include为curl的头文件目录