[C con Clase] Problemas con la librería curl

Rubén Blanco Fernández darkmalka en hotmail.com
Vie Sep 28 02:41:30 CEST 2018


Buenas Salvador,


Gracias por la respuesta. Realmente no me aparecía nada, pero busque la ruta y la puse yo mismo "libcurl.a". No se si es válido o si tendría que autodetectarlo y salir ahí directamente el link.

El caso es que había hecho una cosa mal, no había puesto el link en el linker del compilador C:\MinGW\msys\1.0\local\lib\libcurl.a

Ahora si me devuelve la lista de 50 errores o más:


||=== Build: Debug in  yo curl (compiler: GNU GCC Compiler) ===|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-easy.o)|| undefined reference to `WSAStartup en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-easy.o)|| undefined reference to `WSACleanup en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-easy.o)|| undefined reference to `WSACleanup en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `getsockopt en 20'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `ntohs en 4'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `getpeername en 12'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `getsockname en 12'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `getsockopt en 20'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `setsockopt en 20'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `recv en 16'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `closesocket en 4'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `closesocket en 4'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `socket en 12'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `setsockopt en 20'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSAIoctl en 36'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `setsockopt en 20'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `bind en 12'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `ntohs en 4'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `connect en 12'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `getsockname en 12'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `htons en 4'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-connect.o)|| undefined reference to `WSASetLastError en 4'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-multi.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-multi.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `WSASetLastError en 4'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `select en 20'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| more undefined references to `__WSAFDIsSet en 8' follow|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `select en 20'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `WSAGetLastError en 0'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-select.o)|| undefined reference to `__WSAFDIsSet en 8'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

El caso es que me di cuenta de que  con este código no hay errores

#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
    CURL *curl;
    CURLcode res;
 //   curl = curl_easy_init();
  return 0;
}
Los errores vienen de la linea silenciada, pero puedo declarar las dos variables en verde sin errores. Parece como que se puede acceder de alguna manera a la librería pero de forma incorrecta.
La verdad es que no tengo ni idea, las librerias en windows siempre me traen de cabeza.

Un saludo y gracias.



________________________________
De: Cconclase <cconclase-bounces en listas.conclase.net> en nombre de Salvador Pozo <salvador en conclase.net>
Enviado: jueves, 27 de septiembre de 2018 12:21
Para: cconclase en listas.conclase.net
Asunto: Re: [C con Clase] Problemas con la librería curl

El pasado 2018-09-27 09:04:29, ruben escribió:

r> Hola muy buenas,
r> Estoy intentando utilizar la librería curl en windows para para poder gestionar la API de una web y no soy capaz.

Hola:

¿Has añadido el nombre de la librería estática en las opciones de proyecto?

Busca "Project build optión" y la pestaña "Linker settings". En "Link libraries" deberías tener algo como "curl", depende del nombre de la librería estática.

El formato de nombre para esas librerías es lib<nombre>.a

Generalmente el "nombre" es el mismo que el de la librería, en tu caso "curl". Por ejemplo para SQLite, el nombre es "sqlite", que es el que debe añadirse a las opciones de proyecto, y el nombre del fichero "libsqlite.a". En este caso, el nombre del fichero sería "libcurl.a".

Suerte.

Hasta pronto.





r> Instalé CodeBlocks y MymGW y para instalar Curl abrí msys y escribí esto:
r> $ ./configure --prefix=/usr/local --without-ssl --disable-shared --build=x86_64-w64-mingw32 CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
r> $ make install-strip
r> Y parece que todo fue bien.
r> He ido en CodeBlocks a Settings/Compiler/Search directories y he anadido estas los rutas:
r> C:\MinGW\msys\1.0\local\lib
r> C:\MinGW\msys\1.0\local\include
r> Intento ejecutar este programa, pero me da error:
r> #include <stdio.h>
r> #include <curl/curl.h>
r> int main(void)
r> {
r>   CURL *curl;
r>   CURLcode res;
r>   curl = curl_easy_init();
r>   if(curl) {
r>     curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
Example Domain<https://example.com/>
example.com
Example Domain. This domain is established to be used for illustrative examples in documents. You may use this domain in examples without prior coordination or asking for permission.



r>     /* example.com is redirected, so we tell libcurl to follow redirection */
r>     curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
r>     /* Perform the request, res will get the return code */
r>     res = curl_easy_perform(curl);
r>     /* Check for errors */
r>     if(res != CURLE_OK)
r>       fprintf(stderr, "curl_easy_perform() failed: %s\n",
r>               curl_easy_strerror(res));
r>     /* always cleanup */
r>     curl_easy_cleanup(curl);
r>   }
r>   return 0;
r> }
r> //------------------------------------------------------------------------------------------------------------------------------------------------
r> ||=== Build: Debug in Hello Curl (compiler: GNU GCC Compiler) ===|
r> obj\Debug\main.o||In function `main':|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|9|undefined reference to `_imp__curl_easy_init'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|11|undefined reference to `_imp__curl_easy_setopt'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|13|undefined reference to `_imp__curl_easy_setopt'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|16|undefined reference to `_imp__curl_easy_perform'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|19|undefined reference to `_imp__curl_easy_strerror'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|23|undefined reference to `_imp__curl_easy_cleanup'|
r> ||error: ld returned 1 exit status|
r> ||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
r> 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.
r>  En la propia página de la librería explican esto:
r> https://curl.haxx.se/docs/install.html
r> Important static libcurl usage note
r> 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.
r> 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.
r> He entrado en Settings/Compiler/Compiler setting/Other compiler options y he pegado -DCURl_STATICLIB y el error es:
r> ||=== Build: Debug in Hello Curl (compiler: GNU GCC Compiler) ===|
r> obj\Debug\main.o||In function `main':|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|9|undefined reference to `curl_easy_init'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|11|undefined reference to `curl_easy_setopt'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|13|undefined reference to `curl_easy_setopt'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|16|undefined reference to `curl_easy_perform'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|19|undefined reference to `curl_easy_strerror'|
r> C:\Users\vaklam\Documents\hello Crul\Hello Curl\Hello Curl\main.cpp|23|undefined reference to `curl_easy_cleanup'|
r> ||error: ld returned 1 exit status|
r> ||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
r> 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.
r> Llevo horas con esto y la cosa ha ido evolucionando, pero me he estancado aquí y no se que más probar.
r> Gracias a todos de antemano.
r> Un saludo
r> [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>
r> _______________________________________________
r> Lista de correo Cconclase Cconclase en listas.conclase.net
r> http://listas.conclase.net/mailman/listinfo/cconclase_listas.conclase.net
r> Bajas: http://listas.conclase.net/index.php?gid=2&mnu=FAQ
--
Salvador Pozo (Administrador)
mailto:salvador en conclase.net
Blog con Clase: http://blogconclase.wordpress.com
Con Clase: http://conclase.net
_______________________________________________
Lista de correo Cconclase Cconclase en listas.conclase.net
http://listas.conclase.net/mailman/listinfo/cconclase_listas.conclase.net
Bajas: http://listas.conclase.net/index.php?gid=2&mnu=FAQ

[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>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.conclase.net/pipermail/cconclase_listas.conclase.net/attachments/20180928/26e5a43e/attachment.html>


Más información sobre la lista de distribución Cconclase