1. 程式人生 > >vs2010編譯curl為static庫及測試

vs2010編譯curl為static庫及測試

編譯curl為static庫

  • 用vs2010開啟: curl-7.32.0\vs\vc6\vc6curl.dsw
  • 選擇LIB Release生成libcurl靜態庫: curl-7.32.0\vs\vc6\lib\lib-release\libcurl.lib

重新建立一個testcurl控制檯程式

  • 新增curl標頭檔案:拷貝curl-7.32.0\include\curl  到 testcurl\testcurl 目錄下
  • 拷貝libcrul.lib靜態庫:拷貝curl-7.32.0\vs\vc6\lib\lib-release\libcurl.lib 到testcurl\testcurl 目錄下
  • 新增CURL_STATICLIB 到 前處理器: Property ->Configuration Properties -> C/C++ ->Preprocessor ->Preprocessor Definitions
  • 寫入curl測試程式碼:
#include "stdafx.h"
#include <Windows.h>
#include "curl/curl.h"

#pragma comment(lib, "libcurl.lib") 
#pragma comment(lib, "wldap32.lib") 
#pragma comment(lib, "ws2_32.lib") 
#pragma comment(lib, "winmm.lib") 

int _tmain(int argc, _TCHAR* argv[])
{
	CURL *curl;
	CURLcode res;

	curl = curl_easy_init();
	if(curl) {
		curl_easy_setopt(curl, CURLOPT_URL, "http://2345.com/?kduba");

		res = curl_easy_perform(curl);
		curl_easy_cleanup(curl);
	}
	getchar();
	return 0;
}