2011-03-30 13 views
6
[[email protected] ~]$ g++ client.cpp -lcurl -o client.exe 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x23): undefined reference to `_imp__curl_global_init' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x5f): undefined reference to `_imp__curl_formadd' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x9b): undefined reference to `_imp__curl_formadd' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xa2): undefined reference to `_imp__curl_easy_init' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xc8): undefined reference to `_imp__curl_easy_setopt' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xe4): undefined reference to `_imp__curl_easy_setopt' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xf1): undefined reference to `_imp__curl_easy_perform' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x101): undefined reference to `_imp__curl_easy_cleanup' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x10e): undefined reference to `_imp__curl_formfree' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x11b): undefined reference to `_imp__curl_slist_free_all' 
collect2: ld returned 1 exit status 

no tengo este problema en Linux, así que no sé por qué sucede esto en las ventanas. Ya lo busqué en Google y no encontré nada, excepto los archivos de la lista de correo, con la misma pregunta y respuesta diciendo "google it".¿Cómo resuelvo estos errores de enlace de libcurl?

estoy usando MinGW. Obtuve algunas advertencias del enlazador cuando construí libcurl pero parecían estar relacionadas con SSL y no sé si es un gran problema porque se construyó sin errores.

*** Warning: linker path does not have real file for library -lssl. 
*** I have the capability to make that library automatically link in when 
*** you link to this library. But I can only do this if you have a 
*** shared version of the library, which you do not appear to have 
*** because I did check the linker path looking for a file starting 
*** with libssl and none of the candidates passed a file format test 
*** using a file magic. Last file checked: /ssl/lib/libssl.a 

*** Warning: linker path does not have real file for library -lcrypto. 
*** I have the capability to make that library automatically link in when 
*** you link to this library. But I can only do this if you have a 
*** shared version of the library, which you do not appear to have 
*** because I did check the linker path looking for a file starting 
*** with libcrypto and none of the candidates passed a file format test 
*** using a file magic. Last file checked: /ssl/lib/libcrypto.a 

*** Warning: linker path does not have real file for library -lz. 
*** I have the capability to make that library automatically link in when 
*** you link to this library. But I can only do this if you have a 
*** shared version of the library, which you do not appear to have 
*** because I did check the linker path looking for a file starting 
*** with libz and none of the candidates passed a file format test 
*** using a file magic. Last file checked: /mingw/lib//libz.a 
*** The inter-library dependencies that have been dropped here will be 
*** automatically added whenever a program is linked with this library 
*** or is declared to -dlopen it. 

*** Since this library must not contain undefined symbols, 
*** because either the platform does not support them or 
*** it was explicitly requested with -no-undefined, 
*** libtool will only create a static version of it. 

Respuesta

6

Libtool solo ha creado una libcurl estática y no una biblioteca dinámica. Tus encabezados están buscando un libcurl dinámico. Probablemente no sea culpa de libcurl, porque puedo ver el código en las cabeceras que apoya __declspec(dllimport) y __declspec(dllexport) (eso es una buena señal de que el autor del paquete sabe qué es lo que

Detalles técnicos:.. see this answer regarding libssh

Solución: Compilar con -DCURL_STATICLIB.

+0

Hm. Pensé que libcurl creó tanto estática como dinámica. Intenté -DCURL_STATICLIB pero ahora recibo cientos de errores del enlazador, por ejemplo, referencia indefinida a WSAStartup @ 8, _imp__ares_library_init, ntohs @ 4, getsockopt @ 20 etc. – VVV

+0

http://www.nomorepasting.com/getpaste.php?pasteid= 36044 – VVV

+1

No está enlazando en ninguna de las bibliotecas dependientes. Necesitarás (al menos) -lwinsock2' plus cualquiera que sean los indicadores '-l' para las demás bibliotecas (parece que OpenSSL y posiblemente uno o dos más). –

7

que fue capaz de evitar estos errores que une rizo en windows (Win32 MinGW) mediante la adición de la opción -lcurl.dll. -DCURL_STATICLIB no se necesitaba en mi caso.

mi acumulación tiene dos libcurl archivos en MinGW carpeta/lib: libcurl.a and libcurl.dll.a

+1

Gracias por la ruta de navegación que resuelve mi problema g ++: Código :: Bloques> Configuraciones> Compilador> Configuraciones del enlazador> Agregar> lib \ libcurldll.a && lib \ libcurl.a –

1

estaba teniendo el mismo problema utilizando NetBeans 7.1 con MinGW. De las propiedades, el enlazador que agrega la biblioteca libcurl.dll.a resolvió el problema por mí.

Este archivo se encuentra bajo el rizo-7.28.1 \ lib.libs después me encontré con la marca MinGW.

0

tuve error similar (con libz y libsqlite) en diferentes proyectos. Es producido por GNU libtool script.

La razón en mi caso fue la falta de algunos archivos para estas bibliotecas (.la?) O tal vez libz.dll.a variantes de las bibliotecas.

Para tener todos los archivos necesarios para la construcción de automake/autoconf ./configure --prefix=... ; make, usted tiene que construir zlib, crypto y ssl con configure y make que bajo el mismo MSYS. cmake o compilaciones de archivo make personalizadas generalmente no funcionarán como dependencias para compilación autotool de biblioteca compartida.

Otro y la opción más sencilla es la construcción de rizo dinámico con cmake (https://github.com/bagder/curl.git)

Cuestiones relacionadas