I can't install the cURL library in Code:: Blocks + MinGW

I'm pretty new to c++. There was a need to set libu cURL to Code::Blocks. After reading on the web, I realized that this can be done if:

  • A) Install to compiler -> search directories -> compiler folder include with headers
  • B) Add to compiler -> linker file libcurl.a

Took this code as an example:

#include <iostream>
#include "curl/curl.h"
#define CURL_STATIC

using namespace std;

int main()
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    /* example.com is redirected, so we tell libcurl to follow redirection */
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      cout << "curl_easy_perform() failed: " << curl_easy_strerror(res) << endl;

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
    return 0;
}

The problem is that after these actions, when compiling, there are countless errors by type:

||=== Build: Debug in [ИМЯ ПРОЕКТА] (compiler: GNU GCC Compiler) ===|
...\curl-7.69.0-win32-mingw\curl-7.69.0-win32-mingw\lib\libcurl.a(connect.o)|| undefined reference to `_imp__ntohs@4'|
...\curl-7.69.0-win32-mingw\curl-7.69.0-win32-mingw\lib\libcurl.a(connect.o)|| undefined reference to `_imp__getpeername@12'|
...\curl-7.69.0-win32-mingw\curl-7.69.0-win32-mingw\lib\libcurl.a(connect.o)|| undefined reference to `_imp__WSAGetLastError@0'|

Actually there are more than forty of them

After a long search on the web, I came across one answer(I don't remember where): In compiler -> linker you need to put two files:

  1. libcurl.a
  2. libcurl.dll.a

OK, everything was compiled, BUT when running the program via C:: B(Compile and run) a dialog appears with the following error: Ошибка при запуске приложения (0xc00000be). Для выхода из приложения нажмите "ОК". There is one more remark: If I run the program from the file that generates C:: B, an error will also appear, but the content that is missing on the computer libcurl.dll. Okay, I found it in the archive with cURL, threw it in the directory with the program. Now the error is that there is no libcrypto-1_1.dll. I have no idea where to get this library.

P.S.

Now I realized that I set the wrong bit depth of the library(32). I reinstalled it and did the same thing. Now I have another error =)

||=== Build: Debug in [Имя проекта] (compiler: GNU GCC Compiler) ===|
:(.text.startup+0x2f)||undefined reference to `curl_easy_init'|
:(.text.startup+0x4d)||undefined reference to `curl_easy_setopt'|
:(.text.startup+0x65)||undefined reference to `curl_easy_setopt'|
:(.text.startup+0x6d)||undefined reference to `curl_easy_perform'|
:(.text.startup+0x91)||undefined reference to `curl_easy_strerror'|
:(.text.startup+0xad)||undefined reference to `curl_easy_cleanup'|
||error: ld returned 1 exit status|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Notes:

  1. the header itself C::B finds
  2. when trying to set the curl flag in the linker, error: ld. exe||cannot find -lcurl|

I will be very grateful to the video tutorial on how to do this, so everything will be most clearly visible.


Installed MinGW

Gcc is installed. Version Information:

Thread model: posix
gcc version 8.1.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 

Installed Code:: Blocks version 17.12

CURL Library version curl-7.69.0-win64-mingw; link to the archive '; The archive is unpacked to an arbitrary directory

Windows 7 (64-bit)

The compiler settings are set to static compilation

Author: CppCat, 2020-03-08