C++:Libcururl curl_easy_init() 给出访问冲突错误并使程序崩溃
我正在尝试将 libcurl 与我正在编写的程序一起使用,但我遇到了一些问题。到目前为止,我只尝试了 libcurl 网站上的示例,但是一旦程序进入curl 初始化,它们就会崩溃。
我当前的代码:
#include <iostream>
#include <curl/curl.h>
int main(int argc, char *argv[])
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://garrysmod.fi/");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
我还确保编译器和链接器可以找到资源,并且 dll 文件(libcurl.dll)位于程序的文件夹中,但它不断崩溃。 我尝试使用VS2010进行调试,它在初始化函数curl_easy_init()处给了我一个“访问冲突”错误。
任何帮助将不胜感激!
I'm trying to use libcurl with a program I'm making, but I'm having some problems with it. So far I've only tried the examples from libcurl's website, but they crash as soon as the program gets to the curl initialization.
My current code:
#include <iostream>
#include <curl/curl.h>
int main(int argc, char *argv[])
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://garrysmod.fi/");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
I have also made sure the compiler and linker can find the resources, and that the dll file (libcurl.dll) is in the program's folder, yet it keeps crashing.
I tried debugging with VS2010, and it gave me an "access violation" error at the initialization function curl_easy_init().
Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这几乎肯定是 DLL 不匹配。首先检查您的 PATH 中是否有旧版本或不同版本的 libcurl.dll。
我刚刚使用 VS2010 professional 针对 MSVC 7.18 版本构建了您的代码片段。 0 / Win32 generic 并且工作正常。
This is almost certainly a mismatch of DLL's. Firstly check on your PATH for any older or different versions of libcurl.dll.
I just built your snippet using VS2010 professional against this release for MSVC 7.18.0 / Win32 generic and it worked fine.
程序在我的机器(ubuntu 盒子)上编译正常:
#g++ -lcurl url.c -o url
Program compiled ok on my machine (ubuntu box):
#g++ -lcurl url.c -o url
您可以尝试在发布编译中运行该程序,看看它是否可以正常运行。我注意到,对于我在 Windows 上使用的一些开源库,如果将调试版本与操作系统库的发布版本链接起来,效果就不会很好。然后,我通常会设置编译器选项以链接调试版本中库的调试版本和发布版本中库的发布版本。
不幸的是,我从来没有费心去追查为什么会发生这种情况。这是值得尝试的事情。
You might try running the program in the release compile and see if it works without error. I've noticed that with a few open source libraries that I've used on Windows that if you link the debug build with the release build of the OS library things don't work well. I've typically then set the compiler options to link against the debug version of the library in debug build and the release version of the library in the release build.
I've never bothered to track down why this happens, unfortunately. It's something to try.