How to install libcurl in Dev c++?

Asked

Viewed 123 times

0

I tried to install here but the following code does not compile:

#include <stdio.h>
#include <curl/curl.h>

int main( void )
{
   int a = 1, b, c;
   char post[1000];
   CURL *curl;
   CURLcode res;

   /* In windows, this will init the winsock stuff */
   curl_global_init( CURL_GLOBAL_ALL );

   /* get a curl handle */
   curl = curl_easy_init();
   if ( curl ) {
      // aqui é definido o formulario que recebera os dados da requisição (POST).
      curl_easy_setopt( curl, CURLOPT_URL, "http://127.0.0.1/triangulo.php" );

      while ( a > 0 ) {
         printf( "\nDigite os 3 lados do triangulo separados por espaco: " );
         scanf( "%d %d %d", &a, &b, &c );

         sprintf( post, "n1=%d&n2=%d&n3=%d", a, b, c ); //Aqui é definida as variaveis do POST

         curl_easy_setopt( curl, CURLOPT_POSTFIELDS, post );

         /* Perform the request, res will get the return code */
         res = curl_easy_perform( curl );

         if ( res != CURLE_OK ) // verifica se deu algum erro
            fprintf( stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror( res ) );

      }

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

Errors pointed out by the compiler:

main. c:(.text+0xdc): Undefined Reference to __imp_curl_global_init' main.c:(.text+0xe5): undefined reference to __imp_curl_easy_init' main. c:(.text+0x124): Undefined Reference to __imp_curl_easy_setopt' main.c:(.text+0x1b9): undefined reference to __imp_curl_easy_setopt' main. c:(.text+0x1cc): Undefined Reference to __imp_curl_easy_perform' main.c:(.text+0x1ec): undefined reference to __imp_curl_easy_strerror' main. c:(.text+0x22f): Undefined Reference to __imp_curl_easy_cleanup' main.c:(.text+0x238): undefined reference to __imp_curl_global_cleanup' [error] Ld returned 1 Exit status

inserir a descrição da imagem aqui

How I installed the libcurl:

I simply copied what was in his lib and pasted it into Dev C++ lib, copied what was in the includes, and also threw all the files into Dev C++ includes. I left the image above for you to have an idea. Did I install it right? Why are you making these mistakes? I have tested with more than one example code and always happen the same mistakes, I do not know what to do or try... already reinstalled the program several times to repeat the installation process in different ways and always gives the same errors when compiling...

  • Are you linking to the library? I believe it is -lcurl

  • No... I don’t even know how to do that, can you give me an example? Where do I type this?

  • https://answall.com/questions/309433/howto install.

  • It didn’t work, I went to the Curl file folder. h and it still gives the same errors

  • Ah ok. I see in your screenshot that your Curl-7.72.0 folder is the source code and not the binaries. Have you compiled the library? In the case how you are using Mingw-W64 you will need to compile the . a files and install them in the lib folder, . dll in the bin folder and copy the include folder headers from Curl to the compiler’s include folder. It is a little complicated to install libraries in C/C++, if you keep having difficulties you might want to find a package manager like vcpkg or conan.io.

  • I found a folder called libcurl that I had not yet seen, in it has all those files that the compiler accuses error, where will I have to play that libcurl folder?

  • What files?

  • Compiler error files, for example: main. c:(.text+0xdc): Undefined Reference to __imp_curl_global_init' dai in this folder has a file with that name only with extension . 3 but I think q should be nothing...

  • Try to install the files that are on this link. I don’t have Mingw-W64 to test here, but on the site it is written that they have compiled the library with it. https://curl.haxx.se/windows/dl-7.72.0_2/curl-7.72.0_2-win64-mingw.zip

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.