views:

56

answers:

3

Hello,

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!

A: 

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.

Nathan
Good point, that has worked for me before too. Doesn't seem to in this case, though. Thanks for the answer, anyway.
Dragory
A: 

Use cURLpp ( http://curlpp.org/ ).

simssi
+2  A: 

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.

Richard Harrison
Thank you! I was using the Win32 Generic version of libcurl instead of Win32 MSVC. The program also gave an error message about zlib later on, but that was fixed by downloading and putting zlib1.dll in the program's folder.
Dragory
Excellent news; that's what it looked like to me. For future reference I will generally build against a static lib version if available to find problems caused by DLL hell. I often ship code using static libs precisely to avoid DLL problems. The extra size of exe is worth the reliability improvement.
Richard Harrison