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. UVALive 6931 Can't stop playing (Regionals 2014 >> Europe - Central)

    题目 一开始有一个双头队列,每次添加一个数(这是数是二的幂,所有数的和不大于\(2^13\)),由你来决定添加到队头还是队尾.如果队列里面相邻的两个数相同,设它们都是\(x\),那么这两个数会合并为\ ...

  2. log翻硬币

    若果有一组硬币,(假定有十个),每一个硬币仅仅有两个面,正面用以表示.反面用零表示. 给定目标(初始状态)1111100000 正正正正正反反反反反 (目标状态)   1000011101 正反反反反 ...

  3. 视频播放-SurfaceView

    1.视图 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:too ...

  4. PHP - 验证用户名

    /** * * 函数名:_check_username($user_str,$min_num,$max_num); * 作用:检测用户名是否符合格式 * 参数: * 1:用户名 * 2:不得小于多少位 ...

  5. MySql连接问题

    今天想通过命令连接到另外一台主机的Mysql 命令: mysql -h ip -u username -p EnterPassWord: password 连接成功

  6. java BigDecimal的使用和四舍五入及格式规范(精准数据)

    • Java中的简单浮点数类型float和double不能够进行运算.不光是Java,在其它很多编程语言中也有这样的问题. 如果我们编译运行下面这个程序会看到什么? public   class  T ...

  7. Python学习笔记 — 函数

    函数是对程序逻辑进行结构化或过程化的一种编程方法.函数具有两个方面的意义:1)将代码分块,易于管理和阅读:2)最大化代码复用和最小化代码冗余,节省空间,有助于保持一致性. 1. 函数定义 Python ...

  8. 【剑指offer】从上向下打印二叉树

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/26089165 剑指offer上的第23题,实际上就是考察二叉树的层序遍历,详细思想能够參考 ...

  9. Java中int类型和tyte[]之间转换及byte[]合并

    JAVA基于位移的 int类型和tyte[]之间转换 [java] view plaincopy /** * 基于位移的int转化成byte[] * @param int number * @retu ...

  10. 在Centos 5.4上安装Mysql5.5.10 (整理以前的工作文档)

    1.     安装环境 1.1.  目的 安装Mysql5.5.10服务,提供公司XXXX测试环境.正式环境也采用该版本的mysql 1.2. 硬件环境 PC机:IntelE5300 内存4G 硬盘5 ...