Linux Compile and install Libcurl (with examples) __linux

Source: Internet
Author: User
Tags openssl git clone
Linux Compile and install Libcurl (with examples) Qianghaohao (codenutter)Description: Before compiling any open source code, you can look at the Readme, install and other files, will provide information on how to compile. In this tutorial you can get a lot of compilation installation information by reading the Readme and Git-info files. In Git-info it is obvious that execution:./buildconf generates configure configuration files. All don't want to be here because you can't find configure files. 1. Download Libcurl Source:git clone https://github.com/curl/curl.git 2. Into the Curl project directory implementation./buidconf Generate Configure configuration file: 3. Execute the resulting configure script:./configure--enable-debug Here I only add this parameter, for subsequent debugging, if you want other parameters, you can./configure--help view other optional parameters. Note: I am the default installation OpenSSL, there is no OpenSSL can not find a library problem. If you have to install a, choose the default installation, the installation of their own directory more trouble, but also to configure additional parameters. Detailed view of the project directory under the README. 4.Make 5.Make install default library file installed in/usr/local/lib header file installed in/usr/local/include---> Install to root permissions 6. To/usr/local/lib/, you can view the installed library files: 7. Next, write a test code to use the Libcurl library (this test code downloads the page of the specified URL):The test code is as follows:
Using Curlopt_writefunction to implement Web page download and save function #include <stdio.h>;
#include <stdlib.h>;
 
#include <unistd.h>;
#include <curl/curl.h>;
#include <curl/types.h>;
 
#include <curl/easy.h>;  FILE *FP; Define the file type pointer//This function is to complete the data saving function for curlopt_writefunction and/or size_t write_data (void *ptr, size_t size, size_t nmemb,
    void *stream) {int written = Fwrite (ptr, size, NMEMB, (FILE *) FP);
return written;
    int main (int argc, char *argv[]) {CURL *curl;
		if (argc!= 3) {fprintf (stderr, "Usage:%s URL filename\n", argv[0]);
    Exit (-1);  
    } curl_global_init (Curl_global_all);
    Curl = Curl_easy_init ();  
 
    Curl_easy_setopt (Curl, Curlopt_url, argv[1]);
        if (fp = fopen (argv[2], w)) = = NULL) {curl_easy_cleanup (curl);
    Exit (1);  
    //curlopt_writefunction the subsequent action to the Write_data function processing curl_easy_setopt (curl, curlopt_writefunction, write_data);
    Curl_easy_perform (curl);
    Curl_easy_cleanup (curl); Exit (0); }
Introduction to 8.curl-config Tools:After the Libcurl library is installed, the Curl-config tool is installed, which is designed to view some information about the installed Libcurl. There are a lot of parameters: Curl-config--libs to see our code link libcurl What parameters, this option we use more curl-config--version view L Ibcurl version has more parameters, not one list, curl-config--help view more parameters. 9. Compile link to our test code: 10. Compile complete, download Baidu homepage: Summary:Compiling the installer through the source code, look at the Readme is very important, rather than blindly according to the old routine compiled installation, many times according to the old routine is not workable, and secondly, in our encounter problems can be directly stuck to the error hint to the Chrome browser search bar search, generally in English forums have a very good solution, very Many problems can be found in the http://stackoverflow.com/forum, this forum is really good.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.