From: abhi on
I am using MinGW compiler for creating a Chat Client in C. Whenever i
use any function of winsock2, my program does not compile and it gives
linker Error.

What could be wrong?
I have included winsock2.h in my program.

Here is Error Message
----------------------------------------------------------------------------
Compiler: Default compiler
Building Makefile: "F:\projects\c\chatme\Makefile.win"
Executing make...
make.exe -f "F:\projects\c\chatme\Makefile.win" all
gcc.exe connection.o -o "ChatMe.exe" -L"C:/DevCpp/lib" -mwindows

connection.o(.text+0x32):connection.c: undefined reference to
`gethostbyname@4'
collect2: ld returned 1 exit status

make.exe: *** [ChatMe.exe] Error 1

Execution terminated
------------------------------------------------------------------------------

and my program is
------------------------------------------------------------------------------
#include<winsock2.h>

int main (int argc, char **argv)
{
struct hostent *hostent;
int fd;
struct sockaddr_in sockaddr;

hostent = gethostbyname("scs.msg.yahoo.com");
return 0;
}

Please Help me

From: Ulrich Eckhardt on
abhi wrote:
> I am using MinGW compiler for creating a Chat Client in C. Whenever i
> use any function of winsock2, my program does not compile and it gives
> linker Error.
>
> What could be wrong?
> I have included winsock2.h in my program.
[...]
> make.exe -f "F:\projects\c\chatme\Makefile.win" all
> gcc.exe connection.o -o "ChatMe.exe" -L"C:/DevCpp/lib" -mwindows
>
> connection.o(.text+0x32):connection.c: undefined reference to
> `gethostbyname@4'
> collect2: ld returned 1 exit status

It is not really a general C or C++ question, so this is the wrong forum
for this. IIRC, you need to link with a library though,
try '-lws2_32.lib'.

Uli

--
FAQ: http://ma.rtij.nl/acllc-c++.FAQ.html
Asking smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
From: abhi on
On Mar 27, 10:05 pm, "Ulrich Eckhardt @ Usenet" <dooms...(a)knuut.de>
wrote:
> abhi wrote:
> > I am using MinGW compiler for creating a Chat Client in C. Whenever i
> > use any function of winsock2, my program does not compile and it gives
> > linker Error.
>
> > What could be wrong?
> > I have included winsock2.h in my program.
> [...]
> > make.exe -f "F:\projects\c\chatme\Makefile.win" all
> > gcc.exe connection.o -o "ChatMe.exe" -L"C:/DevCpp/lib" -mwindows
>
> > connection.o(.text+0x32):connection.c: undefined reference to
> > `gethostbyname@4'
> > collect2: ld returned 1 exit status
>
> It is not really a general C or C++ question, so this is the wrong forum
> for this. IIRC, you need to link with a library though,
> try '-lws2_32.lib'.
>
> Uli
>
> --
> FAQ:http://ma.rtij.nl/acllc-c++.FAQ.html
> Asking smart questions:http://www.catb.org/~esr/faqs/smart-questions.html

when i link with the library as you told me it gives me error.

Compiler: Default compiler
Building Makefile: "F:\projects\c\chatme\Makefile.win"
Executing make...
make.exe -f "F:\projects\c\chatme\Makefile.win" all
gcc.exe connection.o -o "ChatMe.exe" -L"C:/DevCpp/lib" -mwindows -
lws2_32.lib

C:\DevCpp\Bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe:
cannot find -lws2_32.lib
collect2: ld returned 1 exit status

make.exe: *** [ChatMe.exe] Error 1

Execution terminated

---------------------------------------------
can you tell me which groups would be suitable to ask this question?

thank you

From: Thomas on
abhi wrote:

> C:\DevCpp\Bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe:
> cannot find -lws2_32.lib

Maybe -l ws2_32.lib instead of -lws2_32.lib will help.