Usuario: anónimo

Usuarios en línea: 1
Invitados: 1

FAQ

Hilo

26m
Problemas con la librería curl
U(ruben) 2018-09-27 09:04:29

Hola muy buenas,

Estoy intentando utilizar la librería curl en windows para para poder gestionar la API de una web y no soy capaz.

Instalé CodeBlocks y MymGW y para instalar Curl abrí msys y escribí esto:

$ ./configure --prefix=/usr/local --without-ssl --disable-shared --build=x86_64-w64-mingw32 CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"

$ make install-strip

Y parece que todo fue bien.

He ido en CodeBlocks a Settings/Compiler/Search directories y he anadido estas los rutas:

C:\MinGW\msys\1.0\local\lib

C:\MinGW\msys\1.0\local\include

Intento ejecutar este programa, pero me da error:

#include <stdio.h>

#include <curl/curl.h>

int main(void)

{

  CURL *curl;

  CURLcode res;

  curl = curl_easy_init();

  if(curl) {

    curl_easy_setopt(curl, CURLOPT_URL, "https://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)

      fprintf(stderr, "curl_easy_perform() failed: %s\n",

              curl_easy_strerror(res));

    /* always cleanup */

    curl_easy_cleanup(curl);

  }

  return 0;

}

//------------------------------------------------------------------------------------------------------------------------------------------------

||=== Build: Debug in Hello Curl (compiler: GNU GCC Compiler) ===|

obj\Debug\main.o||In function `main':|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|9|undefined reference to `_imp__curl_easy_init'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|11|undefined reference to `_imp__curl_easy_setopt'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|13|undefined reference to `_imp__curl_easy_setopt'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|16|undefined reference to `_imp__curl_easy_perform'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|19|undefined reference to `_imp__curl_easy_strerror'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|23|undefined reference to `_imp__curl_easy_cleanup'|

||error: ld returned 1 exit status|

||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Por lo que he leído tiene que ver con el uso de la librería en modo static o dynamic y entiendo que que la librería está instalada como estática.

 En la propia página de la librería explican esto:

https://curl.haxx.se/docs/install.html

Important static libcurl usage note

When building an application that uses the static libcurl library on Windows, you must add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for dynamic import symbols.

Cuando cosntruyes una aplicación que utiliza la librería lib Curl estática en Windows, debes añadir -DCURl_STATICLIB a tus CFLAGS. Si no el linker importará simbolos dinámicos.

He entrado en Settings/Compiler/Compiler setting/Other compiler options y he pegado -DCURl_STATICLIB y el error es:

||=== Build: Debug in Hello Curl (compiler: GNU GCC Compiler) ===|

obj\Debug\main.o||In function `main':|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|9|undefined reference to `curl_easy_init'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|11|undefined reference to `curl_easy_setopt'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|13|undefined reference to `curl_easy_setopt'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|16|undefined reference to `curl_easy_perform'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|19|undefined reference to `curl_easy_strerror'|

C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|23|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)) ===|

Antes de haber hecho eso, había probado a anadir -DCURl_STATICLIB en: botón secundario en el proyecto/Build options/Complier settings/Other complier options y me devolvió una lista de 50 errores,  pero no los había compiado y como no se deshacer lo que hice en Settings/Compiler/Compiler setting/Other compiler options pues ya no tengo esos errores.

Llevo horas con esto y la cosa ha ido evolucionando, pero me he estancado aquí y no se que más probar.

Gracias a todos de antemano.

Un saludo

[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>   Libre de virus. www.avast.com<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>

_______________________________________________

Lista de correo Cconclase Cconclase@listas.conclase.net

http://listas.conclase.net/mailman/listinfo/cconclase_listas.conclase.net

Bajas: http://listas.conclase.net/index.php?gid=2&mnu=FAQ