curlpp是libcurl的C++封装,由于作者本身并不使用Visual Studio(可能并不贴切,但总之作者提供的vs工程并无法直接编译通过并运行),所以在Windows下的构建并不是解压后就可以编译通过。我自己捣鼓了一个多小时,才发现原来是这么回事。于是将编译的过程和注意事项分享如下。
1.curl下载
从这个http://curl.haxx.se/download.html页面下载,我下载的是http://curl.haxx.se/download/curl-7.20.1.tar.gz
2.curlpp下载
从http://curlpp.org/index.php/download这个页面下载, 我下载的是http://curlpp.googlecode.com/files/curlpp-0.7.3.tar.gz
3.编译curl
由于curlpp是对curl的封装,他必须依赖于curl,所以必须先编译curl。我的机器只安装了vs2008,我的步骤如下:
001.直接用vs2008打开curl-7.20.1/vc6curl.dsw,提示升级工程到vc9,点击Finish完成升级,这样你就有了一个vc6curl.sln
002.编译所有工程配置,我这一点问题都没有直接编译通过了,这一步你可以得到的是:
curl-7.20.1/lib/DLL-Debug/
curl-7.20.1/lib/DLL-Release/
curl-7.20.1/lib/LIB-Debug/
curl-7.20.1/lib/LIB-Release/
这四个目录,生成的是DLL还是Lib看目录名就明白了。curlpp默认是用动态链接的方式使用curl,对应的目录/lib/DLL-Debug和lib/DLL-Release中的lib。
4.编译curlpp
001.解压代码后,打开curlpp-0.7.3/curlpp.VC8.vcproj,还是一样提示升级工程到vc9,升级完成。
002. 直接编译会有问题,提示无法找到curl/curl.h等等,我们需要做的事情是:设置$(LIBCURL_PATH)这个宏,把他的值设置成第3步的curl目录。设置的方法是:添加一个系统环境变量或者添加一个VS用户自定义宏,添加的方法可以参考这个:vs2005如何使用用户自定义宏(User Macros)
003.设置好curl的路径后你会发现还是提示你有几个文件找不到:
infos.cpp、option.cpp这两个直接从工程去掉就可以了
LifetimeLibrary.cpp,PrivateMembers.cpp,这两个文件只是工程中的路径错了,改一下属性中的引用路径就可以了,当然要去掉也可以。(在vs的Solution Explorer中进行)
004.编译会提示你找不到libcurl.lib,原因是工程设置中的lib引用目录不对。
修改如下(这个路径其实和你设置的LIBCURL_PATH)这个自定义环境变量所对应的curl目录下的结构有关,按上面的步骤下来的话这里需要修改下):
Project properties/Linker/General/ Additional Library Directory:$(LIBCURL_PATH)/lib/DLL-Debug
Project properties/Linker/Input/Additional Dependencies: libcurld_imp.lib
下面是从README.win32中截取的一段相关说明
Linking with libcurl All versions of this library need libcurl (c library) include files to compile and lib file to link successfully. To build curlpp you first have to set value of LIBCURL_PATH user macro to your installation of libcurl. This macro is used in the project file for VC9 to find include and lib files of libcurl. Steps to set user macro. Select View/Property Manager, double-click curlpp property sheet, go to Common Properties/User Macros/, double-click name of macro you want to modify, modify it and click OK. Filename of libcurl's lib file should be in the form libcurlX.lib where X denotes build category chosen for curlpp. (see Linking with RTL) If it has different name you have to change .lib filename in Project properties/Librarian/Additional Dependencies (when building static library) or Project properties/Linker/Input/Additional Dependencies (when building dynamic library). Linking with static libcurl If you are not going to use libcurl as a dll and you would like to include it into your library/executable by linking to static version of libcurl you have to define preprocessor symbol CURL_STATICLIB. You can do it in Project/Properties/C/C++/Preprocessor/Preprocessor Definitions. By default all StaticLib* configurations define this symbol. If for some reason you would like to build static curlpp library which links do dynamic libcurl library you have to remove CURL_STATICLIB define.
005.编译时还会出现一个错误:
1>c1xx : fatal error C1083: 无法打开源文件:“WIN32”: Permission denied
这个是因为工程设置中的include有非法的路径(应该是boost),去掉就可以了
原来:"$(LIBCURL_PATH)/include";./;include/curlpp;include;"$(BOOST_PATH)"
改成:$(LIBCURL_PATH)/include";include/curlpp;include;
5.好了,编译通过了:) 你可以得到的是:
DebugDynamic/curlpp.dll
ReleaseDynamic/curlpp.dll
DebugDynamic/curlpp.lib
DebugStatic/curlpp.lib
ReleaseDynamic/curlpp.lib
ReleaseStatic/curlpp.lib
6.测试和确认
我需要用curlpp的example来测试下我的使用,但是使用时却发现会有这样的编译错误:
1>------ Build started: Project: CUrlppDemo, Configuration: Debug Win32 ------
1>Compiling...
1>CUrlppDemo.cpp
1>d:/curlpp-0.7.3/include/curlpp/exception.hpp(49) : warning C4275: 非 dll 接口 class“std::runtime_error”用作 dll 接口 class“curlpp::RuntimeError”的基
1> d:/program files/microsoft visual studio 9.0/vc/include/stdexcept(148) : 参见“std::runtime_error”的声明
1> d:/curlpp-0.7.3/include/curlpp/exception.hpp(48) : 参见“curlpp::RuntimeError”的声明
1>d:/curlpp-0.7.3/include/curlpp/exception.hpp(70) : warning C4275: 非 dll 接口 class“std::logic_error”用作 dll 接口 class“curlpp::LogicError”的基
1> d:/program files/microsoft visual studio 9.0/vc/include/stdexcept(21) : 参见“std::logic_error”的声明
1> d:/curlpp-0.7.3/include/curlpp/exception.hpp(69) : 参见“curlpp::LogicError”的声明
1>d:/curlpp-0.7.3/include/curlpp/internal/curlhandle.hpp(183) : warning C4251: “curlpp::internal::CurlHandle::mWriteFunctor”: class“utilspp::Functor
1> with
1> [
1> R=size_t,
1> TList=utilspp::tl::TypeList
1> ]
1>d:/curlpp-0.7.3/include/curlpp/internal/curlhandle.hpp(184) : warning C4251: “curlpp::internal::CurlHandle::mHeaderFunctor”: class“utilspp::Functor
1> with
1> [
1> R=size_t,
1> TList=utilspp::tl::TypeList
1> ]
1>d:/curlpp-0.7.3/include/curlpp/internal/curlhandle.hpp(185) : warning C4251: “curlpp::internal::CurlHandle::mReadFunctor”: class“utilspp::Functor
1> with
1> [
1> R=size_t,
1> TList=utilspp::tl::TypeList
1> ]
1>d:/curlpp-0.7.3/include/curlpp/internal/curlhandle.hpp(186) : warning C4251: “curlpp::internal::CurlHandle::mProgressFunctor”: class“utilspp::Functor
1> with
1> [
1> R=int,
1> TList=utilspp::tl::TypeList
1> ]
1>d:/curlpp-0.7.3/include/curlpp/internal/curlhandle.hpp(187) : warning C4251: “curlpp::internal::CurlHandle::mDebugFunctor”: class“utilspp::Functor
1> with
1> [
1> R=int,
1> TList=utilspp::tl::TypeList
1> ]
1>d:/curlpp-0.7.3/include/curlpp/internal/curlhandle.hpp(188) : warning C4251: “curlpp::internal::CurlHandle::mSslFunctor”: class“utilspp::Functor
1> with
1> [
1> R=CURLcode,
1> TList=utilspp::tl::TypeList
1> ]
1>d:/curlpp-0.7.3/include/curlpp/internal/optionlist.hpp(110) : warning C4251: “curlpp::internal::OptionList::mOptions”: class“std::map<_Kty,_Ty>”需要有 dll 接口由 class“curlpp::internal::OptionList”的客户端使用
1> with
1> [
1> _Kty=CURLoption,
1> _Ty=curlpp::OptionBase *
1> ]
1>d:/curlpp-0.7.3/include/curlpp/internal/slist.hpp(77) : warning C4251: “curlpp::internal::SList::mData”: class“std::list<_Ty>”需要有 dll 接口由 class“curlpp::internal::SList”的客户端使用
1> with
1> [
1> _Ty=std::string
1> ]
1>d:/curlpp-0.7.3/include/curlpp/form.hpp(91) : warning C4251: “curlpp::HttpPost::mForms”: class“std::list<_Ty>”需要有 dll 接口由 class“curlpp::HttpPost”的客户端使用
1> with
1> [
1> _Ty=utilspp::clone_ptr
1> ]
1>d:/curlpp-0.7.3/include/curlpp/internal/optioncontainer.inl(39) : error C2491: “curlpp::internal::OptionContainer
1>d:/curlpp-0.7.3/include/curlpp/internal/optioncontainer.inl(45) : error C2491: “curlpp::internal::OptionContainer
1>d:/curlpp-0.7.3/include/curlpp/internal/optioncontainer.inl(53) : error C2491: “curlpp::internal::OptionContainer
1>d:/curlpp-0.7.3/include/curlpp/internal/optioncontainer.inl(60) : error C2491: “curlpp::internal::OptionContainer
1>d:/curlpp-0.7.3/include/curlpp/internal/optioncontainer.inl(67) : error C2491: “curlpp::internal::OptionContainer
1>d:/curlpp-0.7.3/include/curlpp/internal/optionsetter.inl(36) : error C2491: “curlpp::internal::OptionSetter
1>d:/curlpp-0.7.3/include/curlpp/internal/optionsetter.inl(45) : error C2491: “curlpp::internal::OptionSetter
1>d:/curlpp-0.7.3/include/curlpp/internal/optionsetter.inl(54) : error C2491: “curlpp::internal::OptionSetter
1> with
1> [
1> _Ty=std::string
1> ]
1>d:/curlpp-0.7.3/include/curlpp/option.inl(45) : error C2491: “curlpp::Option
1>d:/curlpp-0.7.3/include/curlpp/option.inl(52) : error C2491: “curlpp::Option
1>d:/curlpp-0.7.3/include/curlpp/option.inl(63) : error C2491: “curlpp::Option
1>d:/curlpp-0.7.3/include/curlpp/option.inl(71) : error C2491: “curlpp::Option
1>d:/curlpp-0.7.3/include/curlpp/option.inl(86) : error C2491: “curlpp::Option
1>d:/curlpp-0.7.3/include/curlpp/option.inl(99) : error C2491: “curlpp::Option
1>d:/curlpp-0.7.3/include/curlpp/option.inl(107) : error C2491: “curlpp::Option
1>d:/curlpp-0.7.3/include/curlpp/option.inl(117) : error C2491: “curlpp::Option
1>d:/curlpp-0.7.3/include/curlpp/option.inl(125) : error C2491: “curlpp::OptionTrait
1>d:/curlpp-0.7.3/include/curlpp/option.inl(131) : error C2491: “curlpp::OptionTrait
1>d:/curlpp-0.7.3/include/curlpp/option.inl(139) : error C2491: “curlpp::OptionTrait
1>d:/curlpp-0.7.3/include/curlpp/option.inl(152) : error C2491: “curlpp::OptionTrait
1>d:/curlpp-0.7.3/include/curlpp/option.inl(160) : error C2491: “curlpp::NoValueOptionTrait
关于curlpp的问题还可以到这里讨论、寻求帮助:
http://groups.google.com/group/curlpp
关于编译的问题还可以看看这里的讨论:http://news.gmane.org/gmane.comp.web.curl.curlpp.general
2010/4/17 22:52 搞定了之前的example编译出错的问题
The End