cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: link error ___imp___select@20 error?

From: Brian Dessent <brian_at_dessent.net>
Date: Mon, 17 Mar 2008 04:41:28 -0700

Ng Qing Xiang wrote:

> Salmanzadeh VS tutorial. I wrote my program, and i used the fopen.c
> example in it. meaning i #include "fopen.c" and wrote my program using
> the example functions (namely, fopen and fget) to open a url file and
> save its contents. When I tired to link the program, this error poped
> up. This error seems specific to the fill_buffer function in fopen.c
> though. when i commented out the lines which calls them (thus
> rendering the program useless), the error is gone.

The error is telling you that the linker saw that a function tried to
call the select() function but there was no such function found in any
library.

The main problem with using that fopen.c example on Windows is that the
example assumes a *nix environment, and select() works much differently
on Windows and *nix. On *nix, select is part of the base C library and
you don't have to specify any special options to link it. It also works
with generic fds, i.e. you can mix files, sockets, etc. in the fdsets.

On Windows, there is no general purpose select(). The Winsock API
provides an implementation of select(), but it is useful only for socket
handles, not for file descriptors (fds). And since it's part of Winsock
you have to include the proper winsock header and link against the
proper library. Normally this means #include <winsock2.h> and linking
with ws2_32.lib (MSVC) or -lws2_32 (mingw). You also have to initialize
winsock, but that is taken care of by curl.

But the more deeper issue is whether that example will work with the
different semantics of the Winsock select. As a default I would guess
that it won't, but there's a chance that it would. In general though
you can't just port over code using select() from *nix unmodified.

Brian
Received on 2008-03-17