问题
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!
回答1:
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.
回答2:
Program compiled ok on my machine (ubuntu box):
#g++ -lcurl url.c -o url
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Garry's Mod Finland - Etusivu</title>
<meta h ....
回答3:
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.
来源:https://stackoverflow.com/questions/4008921/c-libcurl-curl-easy-init-gives-an-access-violation-error-and-crashes-the-pr