473,890 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

winsock/mingw compile problem (undefined reference)

I'm new to c++. Just started learning it 24 hours ago. Am running into a
compile problem. Please, no one waste the effort telling me to google it.
I've been researching it for quite a while with no joy. I got dev-c++ and a
bit of winsock sample code. I've done nothing out of the ordinary. I could
only assume that anyone else that downloaded this software and attempted
this would meet with the same result. The problem lies with either the
compiler or the source. I'm not sure which. Help greatly appreciated.
Compiler output and source to follow.

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Documen ts and Settings\d\My Documents\c\tes t.cpp" -o
"C:\Documen ts and Settings\d\My
uments\c\test.e xe" -I"C:\Dev-Cpp\lib\gcc\min gw32\3.4.2\incl ude" -I"C:\Dev-Cpp\include\c++ \3.4.2\backward "
-I"C:\Dev-Cpp\include\c++ \3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++ \3.4.2"
-I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0x4 6): undefined
reference to `WSAStartup@8'
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0x8 0): undefined
reference to `socket@12'
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0x9 7): undefined
reference to `WSAGetLastErro r@0'
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0xa c): undefined
reference to `WSACleanup@0'
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0xd 0): undefined
reference to `inet_addr@4'
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0xe 5): undefined
reference to `htons@4'
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0x1 0f): undefined
reference to `connect@12'
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0x1 28): undefined
reference to `WSACleanup@0'
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0x1 e5): undefined
reference to `send@16'
C:\DOCUME~1\D\L OCALS~1\Temp/ccWSaaaa.o:test .cpp:(.text+0x2 39): undefined
reference to `recv@16'
collect2: ld returned 1 exit status

Execution terminated

#include <stdio.h>
#include "winsock2.h "

int main() {

// Initialize Winsock.
WSADATA wsaData;
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
printf("Error at WSAStartup()\n" );

// Create a socket.
SOCKET m_socket;
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

if ( m_socket == INVALID_SOCKET ) {
printf( "Error at socket(): %ld\n", WSAGetLastError () );
return 0;

// Connect to a server.
sockaddr_in clientService;

clientService.s in_family = AF_INET;
clientService.s in_addr.s_addr = inet_addr( "" );
clientService.s in_port = htons( 27015 );

if ( connect( m_socket, (SOCKADDR*) &clientServi ce,
sizeof(clientSe rvice) ) == SOCKET_ERROR) {
printf( "Failed to connect.\n" );
return 0;

// Send and receive data.
int bytesSent;
int bytesRecv = SOCKET_ERROR;
char sendbuf[32] = "Client: Sending data.";
char recvbuf[32] = "";

bytesSent = send( m_socket, sendbuf, strlen(sendbuf) , 0 );
printf( "Bytes Sent: %ld\n", bytesSent );

while( bytesRecv == SOCKET_ERROR ) {
bytesRecv = recv( m_socket, recvbuf, 32, 0 );
if ( bytesRecv == 0 || bytesRecv == WSAECONNRESET ) {
printf( "Connection Closed.\n");
if (bytesRecv < 0)
return 0;
printf( "Bytes Recv: %ld\n", bytesRecv );

return 0;
Aug 18 '05 #1
1 31300
Dom wrote:
I'm new to c++. Just started learning it 24 hours ago. Am running into a
compile problem. Please, no one waste the effort telling me to google it.
I've been researching it for quite a while with no joy.

You'd better wasted a few more time googling it:


Choose the *first* occurence.
Aug 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Joonas Paalasmaa | last post by:
Hi, When compiling Sketch's streamfilter C extension the errors below are raised during linking. What could cause the errors? (Python 2.3, MinGw 1.1 with GCC 2.95.3-6, Windows 98) Here are the occurrences of FilterType that may be relevant: ------- C:\sketch\sketch-0.7.12\Filter\filterobj.c: 949: PyTypeObject FilterType = {
by: Greg Ewing (using news.cis.dfn.de) | last post by:
I'm trying to use MingGW32 to compile a Python extension module that links with the Firebird relational database system. I've used pexports/dlltool to create a libgds32_ms.a file containing definitions for linking with gds32.dll, the Firebird interface library. All goes well until the linking, when I get Info: resolving _isc_start_transaction by linking to
by: rhzehr | last post by:
Hi, I have been having an insane amount of trouble trying to compile a GNU Scientific Library example with MinGW on WinXP. I have been able to compile it fine on my linux box and on my windows machine with cygwin. However, when I try to compile it with MinGW I keep getting this error: undefined reference to 'gsl_sf_bessel_J0' I have copied the GSL library files and header files from my cygwin
by: ddh | last post by:
Hi, I download mingw in my system(XP SP2), and extract them in c:\mingw\gcc, so the directories looks like: c:\mingw\gcc\bin, c:\mingw\gcc\include ..., and I added c:\mingw\gcc\bin in my PATH env. It is OK for compiling .c code, but when compiling c++ code, some error will occur. my cpp file:
by: JeffCameron | last post by:
Hi everyone. I am using the latest MinGW that comes with Dev-C++ for Windows. I am getting an impossible linker error when I try to call some functions from a library that I wrote. I am avsolutely sure that the library is linked. I would greatly appreciate a reply from someone who knows the solution to this problem. Here is a simplified version of my problem. In order to reproduce the linking error that I am talking about, use the...
by: newbie73 | last post by:
Going through the tutorial on http://swig.org, I created the example files (pasted below). After generating the _wrap file, I tried compiling (using mingw32) and received a lot of undefined reference compiler errors: ...\build\temp.win32-2.5\Release\example_wrap.o:example_wrap.c:(.text+0x670f): undefined reference to `_imp__PyExc_MemoryError' there are many other similar errors all prefaced with _imp__Py, so I am assuming there is a...
by: mani | last post by:
Hi I'm bringing up an old story once more! I'm on win32 (winxp sp2) python 2.4.4. mingw gcc version is 3.4.5. msys is in c:\msys. mingw is in c:\mingw and python is in c:\pyton24. there is also python24.lib and libpython24.a in c:\python24\libs. when I try to compile this sample code from with command in msys shell I get the results . this subject was discussed a few times over these years and I tried everything in the posts and...
by: eliben | last post by:
On Jun 27, 3:10 pm, eliben <eli...@gmail.comwrote: Problem solved: http://eli.thegreenplace.net/2008/06/28/compiling-python-extensions-with-distutils-and-mingw/
by: LoneWolf | last post by:
Hi im trying to compile some code im developing that uses opengl and glut on mingw(using eclipse as the IDE) but im having linker errors like: g++ -o(OUTPUT).exe (.o files here) -lopengl32 -lglu32 -lglaux -lglut32 Warning: resolving __imp__glEnable by linking to __imp__glEnable@4 Use --enable-stdcall-fixup to disable these warnings Use --disable-stdcall-fixup to disable these fixups Warning: resolving __imp__glBlendFunc by linking to...
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...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.