在 vs2008 中使用 CurlPP

发布于 2024-07-19 06:40:17 字数 901 浏览 8 评论 0原文

我正在尝试使用静态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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

国际总奸 2024-07-26 06:40:17

查看 \include\curlpp\internal\buildconfig.h 文件,其中

CURLPPAPI
CURLPP_INCLUDE_TEMPLATE_DEFINITIONS
CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION

基于这三个宏的值

CURLPP_STATICLIB
BUILDING_CURLPP
CURLPP_SELF_CONTAINED 

定义了以下宏。请在 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

CURLPPAPI
CURLPP_INCLUDE_TEMPLATE_DEFINITIONS
CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION

based on values of these three macros

CURLPP_STATICLIB
BUILDING_CURLPP
CURLPP_SELF_CONTAINED 

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

旧竹 2024-07-26 06:40:17

除了 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.

紫南 2024-07-26 06:40:17

通常,当人们尝试 #include 定义了库的“EXPORT”宏的库的头文件时,会出现此错误。 curpp 必须有一些宏,通常在如下代码中找到:

#ifdef NATIVEDLL_EXPORTS
#define NATIVEDLL_API extern "C" __declspec(dllexport)
#else
#define NATIVEDLL_API __declspec(dllimport)
#endif

并且您在预处理器中定义了 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:

#ifdef NATIVEDLL_EXPORTS
#define NATIVEDLL_API extern "C" __declspec(dllexport)
#else
#define NATIVEDLL_API __declspec(dllimport)
#endif

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文