Comment installer correctement libcurl et à l'associer à un programme c++?

J'ai essayé d'obtenir un programme en c++ pour utiliser libcurl et ne peut pas le comprendre. Lorsque le développement en C++ j'ai l'habitude d'utiliser visual studio, mais ce projet est à l'aide de vi une session ssh à une machine centos à l'aide de VI et g++. J'ai couru yum install curl, yum install libcurl, yuminstall curl-devel et yum install libcurl-devel et ne peut toujours pas obtenir le programme à compiler.

La documentation sur l'API est très bonne et je peut trouver de l'information comment utiliser libcurl une fois qu'il est installé correctement, mais se il est installé, se révèle être une douleur dans le mais.

Le code est:

#include<iostream>
#include<string>
#include<curl/curl.h>
using namespace std;


string data; //will hold the urls contents

size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up)
{ //callback must have this declaration
    //buf is a pointer to the data that curl has for us
    //size*nmemb is the size of the buffer

    for (int c = 0; c<size*nmemb; c++)
    {
        data.push_back(buf[c]);
    }
    return size*nmemb; //tell curl how many bytes we handled
}

int main(void) {

 CURL* curl;

    curl_global_init(CURL_GLOBAL_ALL);
    curl=curl_easy_init();

    curl_easy_setopt(curl, CURLOPT_URL, "https://domain.com");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_USERPWD, "username:password");

    curl_easy_perform(curl);

    cout << endl << data << endl;
    cin.get();

    curl_easy_cleanup(curl);
    curl_global_cleanup();


    return 0;
}

J'obtiens l'erreur suivante lorsque j'essaie de compiler:

/tmp/ccfeybih.o: In function `main':
helloworld.cpp:(.text+0x72): undefined reference to `curl_global_init'
helloworld.cpp:(.text+0x77): undefined reference to `curl_easy_init'
helloworld.cpp:(.text+0x96): undefined reference to `curl_easy_setopt'
helloworld.cpp:(.text+0xb1): undefined reference to `curl_easy_setopt'
helloworld.cpp:(.text+0xcc): undefined reference to `curl_easy_setopt'
helloworld.cpp:(.text+0xe7): undefined reference to `curl_easy_setopt'
helloworld.cpp:(.text+0xf3): undefined reference to `curl_easy_perform'
helloworld.cpp:(.text+0x132): undefined reference to `curl_easy_cleanup'
helloworld.cpp:(.text+0x137): undefined reference to `curl_global_cleanup'
collect2: ld returned 1 exit status

Je ne trouve pas où aller à partir d'ici.

Vous devez ajouter la liaison drapeau dans g++ invocation options. Quelque chose comme g++ ... -lcurl. Ou vous pouvez créer un makefile pour votre projet.
Auriez-vous par hasard connaissez des bons tutoriels sur comment faire cela?
Par exemple, le premier lien à partir de google.
Merci beaucoup pour la question, j'ai eu le même problème et j'ai été de trouver une solution pour un long moment.

OriginalL'auteur Beamer180 | 2012-07-24