Problem in Socket Programming

A

abhi

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
 
D

Dave Vandervies

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.

Neither MinGW nor winsock2 are defined by the C language, which puts
them beyond the scope of comp.lang.c .

If the problem is a Windows problem, comp.os.ms-windows.programmer.win32
would probably be a good place to ask; if it's a MinGW problem,
gnu.gcc.help might be a good first place to ask, but there may be
somewhere MinGW-specific where you'd be better off.

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

It looks like either the linker is improperly installed and you're missing
a library it needs, or you're invoking it incorrectly and it's not being
told to look in a library that it should be looking at.


dave
 
F

Flash Gordon

Dave Vandervies wrote, On 27/03/07 17:52:
It looks like either the linker is improperly installed and you're missing
a library it needs, or you're invoking it incorrectly and it's not being
told to look in a library that it should be looking at.

Of course, reading the comp.lang.c FAQ which describes a similar problem
with maths functions would also point the OP in the right direction.
 
K

Kenneth Brody

abhi said:
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. [...]
connection.o(.text+0x32):connection.c: undefined reference to
`gethostbyname@4'
collect2: ld returned 1 exit status
[...]

Well, sockets are beyond the scope of comp.lang.c, but the problem
isn't socket-specific. Rather, you need to tell the linker to add
the required library to its search. Which library, and how to do
this, is Windows-specific, and perhaps even MinGW-specific. You'll
need to ask in a Windows or MinGW newsgroup for further help.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top