[C++] How to use Winsock to send stuff with UDP?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

[C++] How to use Winsock to send stuff with UDP?

Post by toasty2 »

I'm learning C++ and I'm wanting to send some data using UDP with winsock. All the tutorials I've found are either insanely complex or are for TCP. So, I'm asking here.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

It doesn't want to compile. I'm using Dev-C++ and I've included the following things (which Dev-C++ has):

Code: Select all

#include <iostream>
#include <windows.h>
#include <winsock2.h>
I'm given the following errors upon compiling:

Code: Select all

[Linker error] undefined reference to `WSAStartup@8' 
  [Linker error] undefined reference to `socket@12' 
  [Linker error] undefined reference to `htons@4' 
  [Linker error] undefined reference to `inet_addr@4' 
  [Linker error] undefined reference to `sendto@24' 
  [Linker error] undefined reference to `closesocket@4' 
  [Linker error] undefined reference to `WSACleanup@0' 
  ld returned 1 exit status
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Do they work on other projects? I think you have some issues with the project settings and the included libraries.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Yes, in this case Ws2_32.lib is missing.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

toasty2 wrote:[Linker error] undefined reference to `WSAStartup@8'
http://msdn2.microsoft.com/en-us/library/ms742213.aspx wrote:WSAStartup
The WSAStartup function initiates use of the Winsock DLL by a process
[...]
Requirements
[...]
Library Use Ws2_32.lib.
Post Reply