Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8285147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:23:15+00:00 2026-06-08T11:23:15+00:00

I have been trying to get a c++ program to use libcurl and can’t

  • 0

I have been trying to get a c++ program to use libcurl and can’t figure it out. When developing in C++ I usually use visual studio but this project is using vi an ssh session to a centos machine using VI and g++. I have ran yum install curl, yum install libcurl, yuminstall curl-devel and yum install libcurl-devel and still cannot get the program to compile.

The documentation on the API is pretty good and I can find information how to use libcurl once it is properly installed but getting it installed is proving to be a pain in the but.

The code is:

#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;
}

I get the following error when I try to compile:

/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

I can’t find where to go from here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:23:16+00:00Added an answer on June 8, 2026 at 11:23 am

    The error you are getting is a linker error. The linker is not able to find the curl library.
    You need to specify paths where the linker would search for appropriate libraries at link time.

    in this case (if you have installed lib curl in the standard lib directories e.g. /usr/lib, r /usr/local/lib) the following should work:

    g++ you_file_name.cpp -lcurl

    Otherwise you have to specify the path to the directory where the library can be found.
    for example:

    g++ -L/curl/lib/dir -lcurl you_file_name.cpp.

    When there are multiple libraries to link to, these things become complicated so it is a good idea to use a build-system such as CMake to assist in managing include-directories/library paths and various other things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For few days I have been trying to figure out how to use make
I have been trying to use JSON to store settings for a program. I
I have been trying to setup Symfony2 on Windows so that I can use
I am using QDial in my program and have been trying to get the
I have been trying to get a simple networking test program to run with
I've been trying to get to get a basic v8 program working under visual
I have been trying to figure this little section of my larger project out
I have been trying to use g++ to compile a program with SDL. The
Ok I have been trying every which way to figure this out. I need
I been having trouble trying to figure this out. When I think I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.