1>下载CURL源代码curl-7.26.0.zip

2>用VC2008/2005打开工程curl-7.26.0\lib\libcurl.vcproj,转换下工程并构建,可以直接编译成功!

3>新建个控制台工程测试下刚才编译的静态库libcurl.lib,可以在libcurl\curl-7.26.0\docs\examples目录找个简单的使用curl的例子,在这个工程选项Configuration Properties-| C/C++ -|General -|Additional Include Directories 路径中加入curl7.26\include, 在linker选项卡,指定静态库路径和静态库的名字libcurl.lib,代码如下

  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. #include "curl/curl.h"
  4. int _tmain(int argc, _TCHAR* argv[])
  5. {
  6. CURL *curl;
  7. CURLcode res;
  8. curl = curl_easy_init();
  9. if(curl) {
  10. curl_easy_setopt(curl, CURLOPT_URL, "http://2345.com/?kduba");
  11. res = curl_easy_perform(curl);
  12. curl_easy_cleanup(curl);
  13. }
  14. return 0;
  15. }

此时cpp文件可以编译,但是链接报错

1>testcurl.obj : error LNK2001: unresolved external symbol __imp__curl_easy_init
1>testcurl.obj : error LNK2001: unresolved external symbol __imp__curl_easy_setopt
1>testcurl.obj : error LNK2001: unresolved external symbol __imp__curl_easy_perform
1>testcurl.obj : error LNK2001: unresolved external symbol __imp__curl_easy_cleanup

看样子根本没有链接静态库,虽然刚才指定了库的路径,确认库路径的名字没错,于是看了下curl_easy_init 这个函数的定义,

  1. CURL_EXTERN CURL *curl_easy_init(void);
  2. CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);
  3. CURL_EXTERN CURLcode curl_easy_perform(CURL *curl);
  4. CURL_EXTERN void curl_easy_cleanup(CURL *curl);
  5. /*
  6. * Decorate exportable functions for Win32 and Symbian OS DLL linking.
  7. * This avoids using a .def file for building libcurl.dll.
  8. */
  9. #if (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)) && \
  10. !defined(CURL_STATICLIB)
  11. #if defined(BUILDING_LIBCURL)
  12. #define CURL_EXTERN  __declspec(dllexport)
  13. #else
  14. #define CURL_EXTERN  __declspec(dllimport)
  15. #endif
  16. #else

看到这里于是明白了,如下操作:

在libcurl静态库工程选项Configuration Properties-| C/C++ -| Preprocessor 中加上BUILDING_LIBCURL宏
在测试工程选项Configuration Properties-| C/C++ -| Preprocessor 中加上CURL_STATICLIB宏,然后依次重新构建两个工程

发现测试工程链接不过

1>libcurl_MT.lib(easy.obj) : error LNK2001: unresolved external symbol __imp__WSACleanup@0
1>libcurl_MT.lib(telnet.obj) : error LNK2001: unresolved external symbol __imp__WSACleanup@0
1>libcurl_MT.lib(easy.obj) : error LNK2001: unresolved external symbol __imp__WSAStartup@8
1>libcurl_MT.lib(telnet.obj) : error LNK2001: unresolved external symbol __imp__WSAStartup@8
1>libcurl_MT.lib(tftp.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libcurl_MT.lib(telnet.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libcurl_MT.lib(ftp.obj) : error LNK2001: unresolved external symbol__imp__WSAGetLastError@0
1>libcurl_MT.lib(select.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libcurl_MT.lib(asyn-thread.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libcurl_MT.lib(transfer.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libcurl_MT.lib(sendf.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libcurl_MT.lib(sendf.obj) : error LNK2001: unresolved external symbol __imp__send@16
1>libcurl_MT.lib(telnet.obj) : error LNK2001: unresolved external symbol __imp__send@16
1>libcurl_MT.lib(sendf.obj) : error LNK2001: unresolved external symbol __imp__recv@16
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__recv@16
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__getsockname@12
1>libcurl_MT.lib(ftp.obj) : error LNK2001: unresolved external symbol__imp__getsockname@12
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__getpeername@12
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__ntohs@4
1>libcurl_MT.lib(telnet.obj) : error LNK2001: unresolved external symbol __imp__ntohs@4
1>libcurl_MT.lib(ftp.obj) : error LNK2001: unresolved external symbol__imp__ntohs@4
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__WSASetLastError@4
1>libcurl_MT.lib(curl_addrinfo.obj) : error LNK2001: unresolved external symbol __imp__WSASetLastError@4
1>libcurl_MT.lib(select.obj) : error LNK2001: unresolved external symbol __imp__WSASetLastError@4
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__getsockopt@20
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__setsockopt@20
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__connect@12
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__bind@12
1>libcurl_MT.lib(tftp.obj) : error LNK2001: unresolved external symbol __imp__bind@12
1>libcurl_MT.lib(ftp.obj) : error LNK2001: unresolved external symbol__imp__bind@12
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__htons@4
1>libcurl_MT.lib(curl_addrinfo.obj) : error LNK2001: unresolved external symbol __imp__htons@4
1>libcurl_MT.lib(telnet.obj) : error LNK2001: unresolved external symbol __imp__htons@4
1>libcurl_MT.lib(ftp.obj) : error LNK2001: unresolved external symbol__imp__htons@4
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__closesocket@4
1>libcurl_MT.lib(connect.obj) : error LNK2001: unresolved external symbol __imp__socket@12
1>libcurl_MT.lib(curl_addrinfo.obj) : error LNK2001: unresolved external symbol __imp__freeaddrinfo@4
1>libcurl_MT.lib(curl_addrinfo.obj) : error LNK2001: unresolved external symbol __imp__getaddrinfo@16
1>libcurl_MT.lib(tftp.obj) : error LNK2001: unresolved external symbol __imp__sendto@24
1>libcurl_MT.lib(tftp.obj) : error LNK2001: unresolved external symbol __imp__recvfrom@24
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_unbind_s
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_msgfree
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ber_free
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_memfree
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_value_free_len
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_get_values_len
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_next_attribute
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_first_attribute
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_get_dn
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_next_entry
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_first_entry
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_search_s
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_simple_bind_s
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_init
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_set_option
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_err2string
1>libcurl_MT.lib(ftp.obj) : error LNK2001: unresolved external symbol__imp__listen@8
1>libcurl_MT.lib(ftp.obj) : error LNK2001: unresolved external symbol__imp__accept@12
1>libcurl_MT.lib(select.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
1>libcurl_MT.lib(select.obj) : error LNK2001: unresolved external symbol __imp__select@20
1>libcurl_MT.lib(nonblock.obj) : error LNK2001: unresolved external symbol __imp__ioctlsocket@12
1>libcurl_MT.lib(curl_gethostname.obj) : error LNK2001: unresolved external symbol__imp__gethostname@8

谷歌了下, WSACleanup function msdn  是需要链接Ws2_32.lib,

同样的道理

1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_unbind_s
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_msgfree
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ber_free
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_memfree
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_value_free_len
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_get_values_len
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_next_attribute
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_first_attribute
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_get_dn
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_next_entry
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_first_entry
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_search_s
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_simple_bind_s
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_init
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_set_option
1>libcurl_MT.lib(ldap.obj) : error LNK2001: unresolved external symbol __imp__ldap_err2string

是少了Wldap32.lib

在libcurl静态库工程选项Configuration Properties-|Librarian -| Additional Dependencies 中加上依赖项Ws2_32.lib Wldap32.lib

再依次重编两个工程,就OK了

编译选项设为/MD时候,不需要添加Ws2_32.lib Wldap32.lib

小结:

1>对于开源代码的编译问题,还是要从代码入手,包括注释

2>静态库构建的时候很容易,但是要知道是不是成功的,还得编个测试工程才能知道是不是真的OK

vc2008构建和使用libcurl静态库的更多相关文章

  1. libcurl 静态库编译

    转载:http://www.cnblogs.com/jkcx/p/6406706.html 1.下载最新版的libcurl(官网:http://curl.haxx.se/download.html), ...

  2. Visual Studio 2015 编译生成支持HTTPS协议的libcurl静态库

    由于之前的工作需要使用libcurl 开源项目库 在各种研究后发现无法使用HTTPS协议 后来经过各种翻阅文档,发现需要OpenSSL支持,这个需要自己下载并自己编译生成 lib 或者 dll 至于O ...

  3. iOS静态库及Framework 创建

    本文转自cocoachina,尊重作者的汗水. 讲述的非常透彻,有需要的朋友可以阅读实践.转载请注明出处 //=================以下留着备份==================// 在 ...

  4. 用Visual Studio2017写静态库

    造轮子是一件有趣的事情,VS是一个强大的工具,能胜任超大规模的工程,但是讲真,对不那么大的项目配置起来不是那么友好(网上的其他教程也一点都不友好Orz).这里就展示一下构建一个简单的静态库的正确姿势. ...

  5. 用Visual Studio2017写C++静态库

    造轮子是一件有趣的事情,VS是一个强大的工具,能胜任超大规模的工程,但是讲真,对不那么大的项目配置起来不是那么友好(网上的其他教程也一点都不友好Orz).这里就展示一下构建一个简单的静态库的正确姿势. ...

  6. QT通过静态库调用Go

    ## 编写Go代码 package main import( "fmt" "C" ) //export test func test(str *C.char) ...

  7. 《CMake实践》笔记三:构建静态库(.a) 与 动态库(.so) 及 如何使用外部共享库和头文件

    <CMake实践>笔记一:PROJECT/MESSAGE/ADD_EXECUTABLE <CMake实践>笔记二:INSTALL/CMAKE_INSTALL_PREFIX &l ...

  8. (转)HelloWorld CMake CMake中构建静态库与动态库及其使用

    继续完善Hello World,建立它的共享库, 包括静态库和动态库. 本节的任务: 1,建立一个静态库和动态库,提供HelloFunc函数供其他程序编程使用,HelloFunc 向终端输出Hello ...

  9. 1. CMake 系列 - 从零构建动态库和静态库

    目录 1. 文件目录结构 2. 库文件源代码 3. 编译生成库文件 1. 文件目录结构 首先创建如下目录结构: └── lib ├── build # ├── CMakeLists.txt └── s ...

随机推荐

  1. C/C++取出变量的每一位的值(第一次知道还有QBitArray)

    前写程序最多也只是字节级别操作,用char和memcpy进行一系列内存操作.此次一个sdk,其状态值直接是每位一个标示,所以需要取出每位进行操作.当然CPP也有丰富的位运算操作,但是虽然也学过,知道意 ...

  2. 新鲜出炉的Using Qt 3D to visualize music

    http://blog.qt.io/blog/2016/01/27/using-qt-3d-visualize-music/

  3. HDU-1664-Different Digits(BFS)

    Problem Description Given a positive integer n, your task is to find a positive integer m, which is ...

  4. C# - 使用皮肤

    运行效果: 项目目录结构: 主窗体代码: using System; using System.Collections.Generic; using System.ComponentModel; us ...

  5. ASIHTTPRequest-插件的使用

    链接地址:http://blog.sina.com.cn/s/blog_7b9d64af0101e5uf.html 一.什么是ASIHTTPRequest   ASIHTTPRequest 插件是一个 ...

  6. C#_事件

    C#_事件 概述 今天用来演示事件的例子是模拟实现一个文件下载类,在这个类中我将定义一个DownLoad事件,这个事件用来在文件下载的过程中,向订阅这个事件的用户发出消息,而这个消息将用DownLoa ...

  7. JAVA中extends 与implements有啥区别?

    JAVA中extends 与implements有啥区别?1. 在类的声明中,通过关键字extends来创建一个类的子类.一个类通过关键字implements声明自己使用一个或者多个接口.extend ...

  8. python 读取图片的尺寸、分辨率

    #需要安装PIL模块 #encoding=gbk#--------------------------------------------------------------------------- ...

  9. 使用最新的log4cplus(1.1.1)隔离不同的 log 文件输出

    部分参考了博客. http://www.cppblog.com/tx7do/articles/11719.html 基于脚本配置来过滤log信息 除了通过程序实现对log环境的配置之外,log4cpl ...

  10. linux下tomcat shutdown后 java进程依然存在

    今天遇到一个非常奇怪的问题,如标题所看到的: linux下(之所以强调linux下,是由于在windows下正常),运行tomcat ./shutdown.sh 后,尽管tomcat服务不能正常訪问了 ...