user1818486
user1818486

Reputation: 165

Can't link with libcurl - undefined references to multiple functions

I am currently having Problems compiling a C++ Program on Windows 7 x64.

It fails to compile in every way I try to:

undefined reference to `curl_easy_init'
undefined reference to `curl_easy_setopt'
undefined reference to `curl_easy_setopt'
undefined reference to `curl_easy_perform'
undefined reference to `curl_easy_strerror'
undefined reference to `curl_easy_cleanup'

The Code itself:

#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://steamcommunity.com");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

    res = curl_easy_perform(curl);

    if(res != CURLE_OK)
    {
        fprintf(stderr, "curl_easy_perform() failed %s\n", curl_easy_strerror(res));
    }

    curl_easy_cleanup(curl);
}
else
{
}
return 0;
}

I am compiling with:

g++ -DCURL_STATICLIB -g -o curlprogram curlprogram.cpp -LJ:\Projektpath -lcurl

I've added the libcurl.a in the Path specified by -L and also put libcurl.dll into C:\Windows\System32.

Upvotes: 0

Views: 1970

Answers (2)

skyfree
skyfree

Reputation: 906

First go to Properties > Configuration Properties > VC++ Directories > Include directories. Here, add the curl directory to be found in the include directory of the unzipped Libcurl file (C:\ … \libcurl-7.19.3-win32-ssl-msvc\include\curl).

Go to VC++ Directories > Library directories. Add the Debug directory containing curllib_static.lib, curllib.dll and curllib.lib (C:\Users\Édouard\Documents\Visual Studio 2010\LibCurl\lib\Debug).

Still in Configuration Properties, go to Linker > Input > Additional Dependencies. Here, you have to add the curllib.lib file (C:\ … \lib\Debug\curllib.lib). Type in up to name of the lib file.

The next step consists on adding curllib.dll, libeay32.dll, openldap.dll, and ssleay32.dll in the Debug directory of your project. There all are to be found in the root directory of Libcurl.

Upvotes: 0

Andrey Volk
Andrey Volk

Reputation: 3549

*.a is not used for windows binaries, put libcurl_imp.lib into your -L path and use -lcurl_imp . Try link shared library without -DCURL_STATICLIB

Upvotes: 1

Related Questions