在 vs2008 中使用 CurlPP
我正在尝试使用静态curlpp 库在VS2008 中构建C++ 控制台应用程序。 代码(curpp 示例 00)如下:
#include "stdafx.h"
#include <curlpp/curlpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
using namespace curlpp::options;
int main(int, char **)
{
try
{
// Our request to be sent.
curlpp::Easy myRequest;
// Set the URL.
myRequest.setOpt<Url>("http://example.com");
// Send request and get a result.
// By default the result goes to standard output.
myRequest.perform();
}
catch(curlpp::RuntimeError & e)
{
std::cout << e.what() << std::endl;
}
catch(curlpp::LogicError & e)
{
std::cout << e.what() << std::endl;
}
return 0;
}
我已经下载了源代码,并将包含路径指向源包含文件,但是当我尝试编译时,我在 的内联文件中收到大量错误。 type:
不允许 dllimport 函数的定义
当然很多人都在 vs2008 中使用过 curpp,而我遗漏了一些明显的东西。
I'm trying to build a C++ console app in VS2008 using the static curlpp library. The code - which is curlpp example 00 - is as follows:
#include "stdafx.h"
#include <curlpp/curlpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
using namespace curlpp::options;
int main(int, char **)
{
try
{
// Our request to be sent.
curlpp::Easy myRequest;
// Set the URL.
myRequest.setOpt<Url>("http://example.com");
// Send request and get a result.
// By default the result goes to standard output.
myRequest.perform();
}
catch(curlpp::RuntimeError & e)
{
std::cout << e.what() << std::endl;
}
catch(curlpp::LogicError & e)
{
std::cout << e.what() << std::endl;
}
return 0;
}
I've downloaded the source and have my include path pointed to the source include files, but when I try and compile, I get a boatload of errors in the inline files of the type:
definition of dllimport function not allowed
Surely lots of folks have used curlpp with vs2008 and I'm missing something obvious.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 \include\curlpp\internal\buildconfig.h 文件,其中
基于这三个宏的值
定义了以下宏。请在 README.win32 中了解它们文件并相应地定义上述三个宏。
如果您仍有问题,请告诉我们。
顺便一提; 今天我把curpp的当前版本供下载
curlpp-current.2009.05.21
Take a look at \include\curlpp\internal\buildconfig.h file where there are the following macros defined
based on values of these three macros
Read about them in README.win32 file and define above three macros accordingly.
In case you still have a problem let us know.
By the way; today I put current version of curlpp for downloading
curlpp-current.2009.05.21
除了 Piotr 的答案之外:不要忘记相应地构建 libcurl 本身 - 动态或静态并定义 CURL_STATICLIB 和 CURLPP_STATICLIB (当然,如果构建静态版本)。
顺便说一句:我绝对不喜欢 CURLPP,很难理解如何让它满足我的需要。 您可能希望将纯 libcurl 与您自己的包装器一起使用。
Addition to Piotr's answer: don't forget to build libcurl itself accordingly - dynamically or statically and define CURL_STATICLIB alongside CURLPP_STATICLIB (if building static version, of course).
And on a sidenote: I absolutely didn't like CURLPP, it was hard to understand how to make it do what I need. You might want to use pure libcurl with your own wrapper.
通常,当人们尝试 #include 定义了库的“EXPORT”宏的库的头文件时,会出现此错误。 curpp 必须有一些宏,通常在如下代码中找到:
并且您在预处理器中定义了 NATIVEDLL_EXPORTS。 删除这个定义。 ppcurl 不会被称为“NATIVEDLL_EXPORTS”,它将有自己的名称。
Usually people get this error when they are trying to #include a library's header file with the library's "EXPORT" macro defined. curlpp must have some macro, usually found in code that looks like this:
and you have the NATIVEDLL_EXPORTS defined in the preprocessor. Remove this definition. ppcurl won't be called "NATIVEDLL_EXPORTS", it will have some name of its own.