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. maven常见问题汇总

    package阶段得到的是build目录下编译后的类包(jar),install是把这个包和一些maven的元信息(比如pom.xml)复制到本地仓库,assembly一般是把build结果和一些资源 ...

  2. printf格式控制详解

    format 参数输出的格式,定义格式为 %[flags][width][.precision][length]specifier specifier在最后面.定义了数据类型. Where the s ...

  3. 更好地认知Azure

    编辑人员注释:本文章由 Windows Azure 网站团队项目经理 Erez Benari 撰写. 我们的网站 http://www.windowsazure.com 包含大量信息,并且也在不断添加 ...

  4. Fix Windows 7 Msvcp71.dll And Msvcr71.dll Missing Error

    Fix Windows 7 Msvcp71.dll And Msvcr71.dll Missing Error Fix Msvcp71.dll And Msvcr71.dll Missing Erro ...

  5. 算法练习之DP 求LCM (最长公共子序列)

    1. 对于序列x[1,i]和y[1,j],推导递推公式1.a 假设当前元素同样,那么就将当前最大同样数+12.b 假设当前元素不同.那么就把当前最大同样数"传递"下去 因此递推公式 ...

  6. PB数据管道

    数据管道提供了一种不同数据库之间传递数据和(或)表结构的方法. 数据管道对象 要完毕数据管道的功能须要提供例如以下内容: 须要数据源和目标数据库,并可以和这两个数据库正常联接 须要源数据库中的哪些表: ...

  7. 使用BAT方法结束进程

    @echo off taskkill /f /im GAM.exe taskkill /f /im GCL10.exe http://www.cnblogs.com/FKdelphi/p/501540 ...

  8. Cocos2D-X学习笔记 3 从一个场景切换到还有一个场景

    工厂方法一般写法 StartLayer * StartLayer::create() { StartLayer *sl = new StartLayer(); sl->init(); sl-&g ...

  9. EasyUI - 后台管理系统 - 登陆模块

    效果: --- --- Html代码: <div id="login"> <p>账户:<input type="text" id= ...

  10. Delphi - SEH研究

    技术交流,DH讲解. 前几天一个朋友在弄游戏外挂想带NP调试,就像自己来捕获游戏的异常.好像就要用到SEH这方面的知识.一起研究了一下,这里看下研究 和 在网上找的资料吧.SEH就是Structure ...