473,406 Members | 2,849 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,406 software developers and data experts.

winsock/mingw compile problem (undefined reference)

Dom
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:\Documents and Settings\d\My Documents\c\test.cpp" -o
"C:\Documents and Settings\d\My
uments\c\test.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -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\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0x46): undefined
reference to `WSAStartup@8'
C:\DOCUME~1\D\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0x80): undefined
reference to `socket@12'
C:\DOCUME~1\D\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0x97): undefined
reference to `WSAGetLastError@0'
C:\DOCUME~1\D\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0xac): undefined
reference to `WSACleanup@0'
C:\DOCUME~1\D\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0xd0): undefined
reference to `inet_addr@4'
C:\DOCUME~1\D\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0xe5): undefined
reference to `htons@4'
C:\DOCUME~1\D\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0x10f): undefined
reference to `connect@12'
C:\DOCUME~1\D\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0x128): undefined
reference to `WSACleanup@0'
C:\DOCUME~1\D\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0x1e5): undefined
reference to `send@16'
C:\DOCUME~1\D\LOCALS~1\Temp/ccWSaaaa.o:test.cpp:(.text+0x239): 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() );
WSACleanup();
return 0;
}

// Connect to a server.
sockaddr_in clientService;

clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( 27015 );

if ( connect( m_socket, (SOCKADDR*) &clientService,
sizeof(clientService) ) == SOCKET_ERROR) {
printf( "Failed to connect.\n" );
WSACleanup();
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");
break;
}
if (bytesRecv < 0)
return 0;
printf( "Bytes Recv: %ld\n", bytesRecv );
}

return 0;
}
Aug 18 '05 #1
1 30955
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:

http://www.google.es/search?hl=gl&q=...Procurar&meta=

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

0
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...
0
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...
4
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...
2
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...
10
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...
0
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...
0
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...
2
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/
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
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,...
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
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.