Page 1 of 1

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

Posted: Sat Jun 23, 2007 3:19 pm
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.

Posted: Sat Jun 23, 2007 6:59 pm
by volka

Posted: Sun Jun 24, 2007 11:54 pm
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

Posted: Mon Jun 25, 2007 5:08 am
by superdezign
Do they work on other projects? I think you have some issues with the project settings and the included libraries.

Posted: Mon Jun 25, 2007 6:06 am
by volka
Yes, in this case Ws2_32.lib is missing.

Posted: Mon Jun 25, 2007 6:25 am
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.