By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,795 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,795 IT Pros & Developers. It's quick & easy.

Problem in Socket Programming

P: n/a
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

Mar 27 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <11**********************@p15g2000hsd.googlegroups .com>,
abhi <ab*******@gmail.comwrote:
>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

--
Dave Vandervies dj******@csclub.uwaterloo.ca

Oh, imagine a psychotic implementor (the best kind) ...
--Peter Seebach in comp.lang.c
Mar 27 '07 #2

P: n/a
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.
[...]
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:Th*************@gmail.com>
Mar 27 '07 #3

P: n/a
Dave Vandervies wrote, On 27/03/07 17:52:
In article <11**********************@p15g2000hsd.googlegroups .com>,
abhi <ab*******@gmail.comwrote:
<snip>
>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.
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.
--
Flash Gordon
Mar 27 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.