473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem in Socket Programming

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
3 3377
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WIWA | last post by:
Hi, I want to make a UDP client server application that is conform to RFC868 (Time protocol). Both the UDP client and UDP server are in a test phase. The question is: when I add ...
9
by: Harshit | last post by:
I am working on socket programming, encountered a new and strange problem today. I am using #define PORT 80, before main(), and I am calling PORT in one of the statments inside main(), I get an...
2
by: chellappa | last post by:
Hi Every body!, i did a small Chat program in Linux C Socket Programm ... I am using stdout/stdin i did in single machinee i will work properly..but i want to run in differnet machine..i tried...
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
1
by: Ryman | last post by:
Hello, I've just recently began network programming for c# (bought the book C# Network Programming) and I've ran into a few problems. Whenever I click the submit button on the client (to send the UDP...
10
by: Uma - Chellasoft | last post by:
Hai, I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can...
0
by: shonen | last post by:
I'm currently attempting to connect to a shoutcast server pull down the information from here and then I'll parse it. I got this working with the httplib, which was great, the problem is I want...
8
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi all, I am new to .net technologies. ASP.NET supports socket programming like send/receive in c or c++? I am developing web-site application in asp.net and code behind is Visual C#. In...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.