编译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

vs2010编译curl为static库及测试 - 图1

重新建立一个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测试代码:
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. #include "curl/curl.h"
  4. #pragma comment(lib, "libcurl.lib")
  5. #pragma comment(lib, "wldap32.lib")
  6. #pragma comment(lib, "ws2_32.lib")
  7. #pragma comment(lib, "winmm.lib")
  8. int _tmain(int argc, _TCHAR* argv[])
  9. {
  10. CURL *curl;
  11. CURLcode res;
  12. curl = curl_easy_init();
  13. if(curl) {
  14. curl_easy_setopt(curl, CURLOPT_URL, "http://2345.com/?kduba");
  15. res = curl_easy_perform(curl);
  16. curl_easy_cleanup(curl);
  17. }
  18. getchar();
  19. return 0;
  20. }

image.jpeg