473,671 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(.t ext+0x32):conne ction.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<winsoc k2.h>

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

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

Please Help me

Mar 27 '07 #1
3 3389
In article <11************ **********@p15g 2000hsd.googleg roups.com>,
abhi <ab*******@gmai l.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.program mer.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):conn ection.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(.t ext+0x32):conne ction.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************ **********@p15g 2000hsd.googleg roups.com>,
abhi <ab*******@gmai l.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):conn ection.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
13241
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 "svrsocket.sendto(resultaat, (ip, port))" in the UDP server, my application closes while running. When I leave it away, it works fine. I really need this statement as the purpose is that a client sends sth to the server and the server sends back the
9
2036
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 error, I don't know why this error is occuring. If i remove PORT in the statement and substitute it by 80, my code works fine. I am sure that #define works in C, any idea why my code is not
2
6985
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 ,but its faliure... try to modify this pgm run in differnt machine Server Program ============== #include <stdio.h> #include <sys/socket.h>
5
3679
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 but have been unsuccessful in finding the answers so far. Either because my understanding of sockets isn't where it needs to be or my questions are too basic. My programming environment is Windows XP, Visual Studio .NET 2003 and C#. So here it...
1
9299
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 packet to the UDP server), it doesn't work the first time (so it seems) and I must click it again to get the server to receive the packet and display it in a List Box. I was wondering if somone could help me track this problem down, I'm sure it's...
10
4024
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 anyone please help me with some sample codings and guidance? Can you also suggest some other news group available for socket programming in VB.Net?
0
1897
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 to use the select statement to do only do this periodically. (I'm trying to be a client, accepting data, that might be my first problem) Basically this is the code that im working on to TEST to mimic what the httplib does, only return a socket...
8
4671
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 page_load event, I am using atl com component. Here one for loop is there. In this for loop, number of iterations are 1000, I can receive some data using com component. It is just set of some characters like
0
3573
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 supposed to do the following: monitor ALL INCOMING TCP traffic on the local computer, and save certain parts of it as files - not log files though, but actual files that are sent to the computer as part of http or ftp. Basically if a user browse a page...
1
20611
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 I don't see the error): "System.IO.IOException: Unable to read data from the transport connection:A blocking operation was interrupted by a call to WSACancelBlockingCall"
0
8478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8919
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8599
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7439
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2813
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.