Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libcurl C++: How to correctly install and use on CentOS 7

Goal:

To correctly install and use libcurl C++ on CentOS 7.

Current output:

When I go to compile a program using libcurl with the command g++ somefile.cpp -lcurl -std=c++11 -o somefile, the following error is received:

[user@localhost ~]$ somefile.cpp -lcurl -std=c++11 -o somefile
somefile.cpp:10:23: fatal error: curl/curl.h: No such file or directory
#include <curl/curl.h>
                       ^
compilation terminated.

Details:

libcurl was installed via sudo yum install libcurl (and also an attempt with sudo yum install libcurl4-openssl-dev). From previous experiences with installing libcurl on Ubuntu 20.04.1 LTS, if I remember correctly I solved a similar issue by setting the LD_LIBRARY_PATH to point to a libcurl.so object as seen below, but this seems to have no effect on CentOS 7.

[user@localhost ~]$ export LD_LIBRARY_PATH=/usr/local/lib/libcurl.so.4
[user@localhost ~]$ sudo ldconfig

If I run the following command I can see the libcurl version which leads me to believe it has been correctly installed:

[user@localhost ~]$ curl --version
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.53.1 zlib/1.2.7 libidn/1.28 libssh2/1.8.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp 
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets

Please note: the following resources have been consulted before deciding to ask this question:

  1. https://lynxbee.com/how-to-resolve-fatal-error-curl-curl-h-no-such-file-or-directory-for-ubuntu-linux/
  2. Ubuntu - #include <curl/curl.h> no such file or directory
  3. curl.h no such file or directory
  4. How do I link libcurl to my c++ program in linux?

Summary question:

q1. How can this error be solved when trying to compile a C++ program using libcurl on CentOS 7?

like image 725
p.luck Avatar asked Sep 21 '25 08:09

p.luck


1 Answers

You will need to install the libcurl-devel package as it contains the headers files you are missing.

The libcurl-devel package includes header files and libraries necessary for developing programs which use the libcurl library. It contains the API documentation of the library, too

like image 170
Mr.Christer Avatar answered Sep 22 '25 23:09

Mr.Christer