2011-03-30 58 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 

Tôi không có vấn đề này trên Linux vì vậy tôi không biết tại sao điều này xảy ra trên cửa sổ. Tôi googled nó đã và không tìm thấy bất cứ điều gì ngoại trừ danh sách gửi thư lưu trữ với cùng một câu hỏi và trả lời nói rằng "google nó".Làm cách nào để giải quyết các lỗi liên kết libcurl này?

Tôi đang sử dụng mingw. Tôi đã nhận được một số cảnh báo mối liên kết khi tôi xây dựng libcurl nhưng họ dường như là ssl liên quan và tôi không biết nếu nó là một việc lớn vì nó được xây dựng mà không có lỗi.

*** 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. 

Trả lời

6

Libtool chỉ xây dựng một libcurl tĩnh chứ không phải thư viện động. Tiêu đề của bạn đang tìm kiếm một libcurl động. Đó có lẽ không phải là lỗi libcurl, bởi vì tôi có thể nhìn thấy mã trong tiêu đề email có hỗ trợ __declspec(dllimport)__declspec(dllexport) (đó là một dấu hiệu tốt tác giả gói biết những gì là những gì

Chi tiết kỹ thuật:.. see this answer regarding libssh

Giải pháp: Biên soạn với -DCURL_STATICLIB.

+0

Hm. Tôi nghĩ libcurl được xây dựng cả tĩnh và động. Tôi đã thử -DCURL_STATICLIB nhưng bây giờ tôi nhận được hàng trăm lỗi liên kết không xác định tham chiếu đến WSAStartup @ 8, _imp__ares_library_init, ntohs @ 4, getockopt @ 20, v.v. – VVV

+0

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

+1

Bạn không liên kết trong bất kỳ thư viện phụ thuộc nào. Bạn sẽ cần (ít nhất) -lwinsock2' cộng với bất kỳ cờ '-l' nào cho các thư viện khác (nó trông giống như OpenSSL và có thể một hoặc hai người khác). –

7

tôi đã có thể tránh được những curl nối lỗi trên cửa sổ (mingw win32) bằng cách thêm tùy chọn -lcurl.dll. -DCURL_STATICLIB không cần thiết trong trường hợp của tôi.

build của tôi có hai tệp libcurl trong thư mục mingw/lib: libcurl.a and libcurl.dll.a

+1

Cảm ơn bạn đã tìm hiểu về vấn đề của mình g ++: Code :: Blocks> Settings> Compiler> Linker settings> Add> lib \ libcurldll.a && lib \ libcurl.a –

1

Có vấn đề tương tự khi sử dụng netbeans 7.1 với mingw. Từ các thuộc tính, linker thêm thư viện libcurl.dll.a giải quyết vấn đề cho tôi.

Tệp này nằm dưới curl-7.28.1 \ lib.libs sau khi tôi chạy mingw make.

0

Tôi có lỗi tương tự (với libz và libsqlite) trong các dự án khác nhau. Nó được tạo bởi tập lệnh GNU libtool.

Lý do trong trường hợp của tôi thiếu một số tệp cho các thư viện này (.la?) Hoặc có thể là libz.dll.a các biến thể của thư viện.

Để có tất cả các file cần thiết cho automake/autoconf build ./configure --prefix=... ; make, bạn sẽ phải xây dựng zlib, cryptossl với configuremake đến dưới cùng MSYS. cmake hoặc xây dựng makefile tùy chỉnh thường sẽ không hoạt động như phụ thuộc cho xây dựng autotool thư viện được chia sẻ.

Tùy chọn khác và đơn giản nhất là xây dựng curl động bằng cmake (https://github.com/bagder/curl.git)

Các vấn đề liên quan