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/

相关文章:

c++ - 涉及转换函数的棘手情况?

C++ cURL 链接错误 "unresolved external symbol _curl_easy_"

java - 区分源代码中的文字和变量/符号

c# - 从对象列表到具有两个属性的字典的优雅方式

c++ - 加载主 QT/QML GUI 窗口会减慢启动画面的渲染速度

C++ 重载运算符时更改操作数顺序

visual-studio - “Call Stack” for Visual Studio 2005中的C++错误

excel - Microsoft Office 互操作程序集引用

string - 在每个给定输入文本中查找每个给定模式首次出现的算法

python - string.translate 函数中的 "table"是什么意思?