Libcurl is an open-source, cross-platform network transmission library for compiling data transmission functions in programs

foreword

libcurl The full name of libcurl is "Client URL", which is the client URL library. It is an open source, cross-platform network transmission library for implementing data transmission functions in programs. libcurl provides a set of easy-to-use APIs , which can be used for data transmission of HTTP, HTTPS, FTP, FTPS, SCP, SFTP, LDAP, SMTP and other protocols.

1. Key features and functions of libcurl

  • Multi-protocol support: libcurl supports multiple network protocols, making it a general-purpose network transport solution. You can use libcurl to handle HTTP requests, download files, upload files, send emails, connect to FTP servers, and more.

  • Cross-platform: libcurl runs on various operating systems, including Windows , macOS , Linux , etc., making it ideal for developing cross-platform applications.

  • Lightweight: libcurl is a lightweight library with a relatively small code base, so it can be used in resource-constrained environments.

  • Easy to integrate: The API design of libcurl is simple and easy to use, and can be easily integrated into C, C++, Python, Java and other programming languages.

  • Support for proxies and cookies: libcurl supports HTTP proxies and can perform data transfers on proxy servers. It also supports cookie management, making it easier to maintain session state across multiple requests.

  • SSL/TLS support: libcurl can use OpenSSL , libressl and other libraries to provide secure socket layer (SSL) and transport layer security (TLS) support, so as to achieve secure HTTPS transmission.

  • Support FTP upload and download: libcurl provides a powerful FTP function, which can be used to upload and download files to the FTP server.

  • Resumable upload: libcurl supports resumable upload function, which allows you to resume the transfer after the transfer is interrupted, and continue transferring files from where it was interrupted last time.

Due to its powerful and flexible functions, libcurl is widely used in various applications and projects. Whether it is developing command-line tools, or building websites and client applications, libcurl is a reliable choice that can help you easily achieve various network transmission needs.

2. Do not use openssl and libssh2 to compile libcurl files and use openssl and libssh2 to compile

The difference is whether to link the OpenSSL and libssh2 libraries when compiling libcurl . Let's explain in detail:

  • Compile libcurl without OpenSSL and libssh2:

    • If the OpenSSL and libssh2 libraries are not linked when libcurl is compiled , the generated libcurl will not support secure transfer protocols such as HTTPS and SFTP **(SSH File Transfer Protocol)**.
    • This means that you cannot use the libcurl library for secure data transfers over HTTPS or SFTP .
  • Compile libcurl with OpenSSL and/or libssh2:

    • If the OpenSSL and/or libssh2 libraries are linked when libcurl is compiled , then the generated libcurl will support secure transport protocols such as HTTPS and/or SFTP .
    • This means you can use the libcurl library for secure data transfers over HTTPS or SFTP .

It should be noted that HTTPS uses the OpenSSL library, while SFTP uses the libssh2 library. Both libraries provide the functionality needed for encryption and secure transmission.

Therefore, if you want to support secure protocols such as HTTPS and SFTP in libcurl , you need to link OpenSSL and libssh2 or other libraries that provide corresponding functions when compiling . Otherwise, libcurl will only work with transfer protocols that don't involve encryption (like HTTP , FTP , etc.).

Use libcurl to facilitate network communication in your program, while by linking OpenSSL and libssh2 , you can ensure that communication is secure and sensitive data can be transmitted encrypted.

3. Download libcurl network library

github address: libcurl download . What I downloaded is: I downloaded
insert image description here
it. After downloading, the file inside looks like this:
insert image description here

4. Compilation of libcurl network library

4.1. Compile directly using cmake, without using the libcurl library compiled from OpenSSL and libssh2 libraries

  • Find the location of the camkeLists.txt file in the folder :
    insert image description here
  • can be seen:
    insert image description here
  • Open the .sln solution file to generate a solution file:
    insert image description here
  • You can see that two library files, libcurl-d.lib and libcurl-d.dll, are generated : here is the libcurl library compiled
    insert image description here
    insert image description here
    without using OpenSSL and libssh2 libraries . I have already mentioned this library and the use of OpenSSL and libssh2 libraries . The difference between the compiled libcurl library.

4.2. The libcurl library compiled using OpenSSL and libssh2 library

  • First open the generate.bat file under the directory curl-7.83.1\curl-7.83.1\projects to generate the configuration environment: Then I choose VC12 , here is visual studio 2013 to compile. I have indicated what the following types of representatives mean in my previous article.
    insert image description here

  • Open the cur-all.sln solution file:
    insert image description here

  • Directly generating the solution will report the following error: This is because the libssh2
    insert image description here
    library file must be included in order to compile through this compilation .

  • libssh2 official address: libssh2 address . I downloaded this version: download link .
    insert image description here

  • After downloading it will look like this:
    insert image description here

  • It is also compiled with cmake , here is the same as compiling libcurl above , not much to say, the compiled library, copy the libssh2.lib and include header files to the directory where you want to compile and use libcurl :
    insert image description here

  • Create a libssh2 file in the libcurl directory to store library files and header files:
    insert image description here

  • Then do this in your solution:
    insert image description here

  • Additional library directories:
    insert image description here

  • Enter the library directory, and rebuild the solution:
    insert image description here

  • The following error was reported again. Is this error familiar with the previous error? This is the library file to include openssl :
    insert image description here

  • Openssl library download address: official address I downloaded this address: download address . Here, the suffix with light and without light are: Note, do not download the light version, because the light version does not include library files.
    insert image description here

  • The downloaded files include these:
    insert image description here
    insert image description here

  • Also copy the library files and header files to the files in libcul :
    insert image description here

  • Also add header files and library files to the solution properties:
    insert image description here
    insert image description here

insert image description here

  • Regenerating the solution again gave the following error, because the libcurl network library also includes libcryproto.lib cryptography library and libcrld.lib :
    insert image description here
  • Among them, libcrypto.lib is also in the openssl library file. Just copy it over.
    insert image description here
  • The following error occurs when generating the solution again. This is because I am using libssh2.lib instead of libssh2d.lib . Just delete it in the properties:
    insert image description here
  • Generate the solution again to finish compiling:
    insert image description here

Guess you like

Origin blog.csdn.net/qq_44918090/article/details/132106796