c++ - libcurl 的标准字符串问题 - C++

标签 c++ string visual-studio-2005 libcurl

我是 C++ 的新手,我正在使用 libcurl 发出 http 请求并返回包含响应内容的字符串。

size_t write_to_string(void *ptr, size_t size, size_t count, void *stream) {
    ((std::string*)stream)->append((char*)ptr, 0, size*count);
    return size*count;
}

int main(void) {

    CURL *curl;
    CURLcode res;
    curl = curl_easy_init();

  if (curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.browsarity.com/");

    std::string response;
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);

    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);

    // The "response" variable should now contain the contents of the HTTP response
  }
  return 0;
}

运行上面的代码后(使用 VS2005)我得到这个错误:

1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(stdthrow.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z)

这似乎是某些库的问题,我尝试添加“msvcrtd.lib”,但我仍然收到上述错误以及其他新错误。

回答: 我将运行时库从多线程 (/MT) 更改为多线程调试 DLL (/MDd)。

最佳答案

您需要下载并编译源代码以获取您的 DLL/库文件。我在为 VS 2005 下载的二进制版本中遇到了类似的调试和链接问题。确保在编译器选项中包含 header 和库路径,并链接 libcurl.dll 等。只需将其放在工作目录或 system32 文件夹中。

关于c++ - libcurl 的标准字符串问题 - C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2395300/

相关文章:

winapi - 查看故障转储中的寄存器

asp.net - 运行 asp.net 项目时,我得到 : Internet Explorer cannot display the webpage

c++ - 如果字节缓冲区应为无符号字符,我是否必须一直保持强制转换?

c - 如何将逗号分隔的 char* 转换为 C 中的 uint32_t[] 数组

c - 从字符串文字初始化的数组是否与从单个字符初始化的数组相同?

string - Typescript 类型 'string' 不可分配给类型 'never' 。错误

c++ - Visual Studio (C++) - 关于目录配置的最佳实践是什么?

c++ - 接口(interface)上的 Release 调用是否确保 COM 组件被销毁

c++ - 在 C++14 允许的情况下,C++17 是否禁止复制省略?

c++ - 计算变化数组中的预期反转次数