This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problems linking against libcurl under cygwin


At 12:46 PM 11/7/2004, you wrote:
>Hi - New to Cygwin for development, not new to development.
>
>Have a project that uses libcurl which will not link under Cygwin.  All of the
>basic libcurl APIs show up as unresolved in the link process.
>
>Example:
>
>gcc -L/usr/local/lib -lcurl -shared ../../shared/htmlparse/htmlparse.o ../../sha
>red/wwwfetch/wwwfetch.o ../shared/free.o key.o -o key.so
>key.o(.text+0x3ae):key.c: undefined reference to `_curl_global_init'
>key.o(.text+0x3b3):key.c: undefined reference to `_curl_easy_init'
>key.o(.text+0x420):key.c: undefined reference to `_curl_easy_setopt'
>key.o(.text+0x42b):key.c: undefined reference to `_curl_easy_perform'
>key.o(.text+0x436):key.c: undefined reference to `_curl_easy_cleanup'
>collect2: ld returned 1 exit status
>make: *** [key.so] Error 1
>
>I believe I have checked all the obvious things.
>
>1) libcurl.a is located in /lib
>2) libcurl is in my library path (obviously)
>3) libcurl.a is being linked against (if I change -lcurl to -lcurlx I get an
>error for not finding the library)
>4) I've tried using both libcurl binaries from Cygwin and building libcurl
>from sources
>5) I also tried linking against libcurl.dll.a as well, makes no difference.
>
>This same code links, runs, etc under FreeBSD and Linux just fine.
>
>Are there special linking requirements under Cygwin or something obvious I'm
>missing?


You're missing the importance of link order.  See 'man ld'.  I created the 
following small example:

# cat t.c
#include <curl/curl.h>

int main()
{
    curl_global_init(0);
    return 0;
}

# gcc -c t.c
# gcc -lcurl -shared ./t.o -o t.so
./t.o(.text+0x26):t.c: undefined reference to `_curl_global_init'
collect2: ld returned 1 exit status
# gcc --shared -o t.so ./t.o -lcurl
#

BTW, it's recommended that you not use the '.so' extension on Windows.  
Windows creates DLLs, not shared objects.  Using '.so' as the extension
may or may not be a problem for you in your case.  But it is something 
you should be aware of.

BTW, if it is not obvious from the above, your link problem is not a Cygwin
issue.  You'd see this link problem on the other platforms you mentioned.


--
Larry Hall                              http://www.rfk.com
RFK Partners, Inc.                      (508) 893-9779 - RFK Office
838 Washington Street                   (508) 893-9889 - FAX
Holliston, MA 01746                     


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]