Q:

Defining function body outside class declaration is not compiling

I was trying to define function that was declared in class (in header .h file). But there are still compiling problems with this separated definition. No matter if it is in these same file with declaration or in separated .cpp it still return these same error

||=== Build: Debug in Server (compiler: GNU GCC Compiler) ===|
obj\Debug\SocketManager.o||In function
`ZN13SocketManager12setUpWINSOCKEv':|
J:\CodeBlocksProjects\Server\SocketManager.h|18|undefined reference to
`WSAStartup@8'| ||error: ld returned 1 exit status| ||=== Build
failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

#include <iostream>
#include <winsock2.h>

using namespace std;

class SocketManager
{
private:
   WSADATA wsaData;
public:
   void setUpWINSOCK();
   SocketManager(int = 27015, string = "127.0.0.1");
};

void SocketManager::setUpWINSOCK()
{
int result = WSAStartup( MAKEWORD( 2, 2 ), & wsaData );
if( result != NO_ERROR )
   cout<<"Initialization error.\n"<<endl;
}

With small change its compilling propetly, but i would like to make it work with separated definition in diffrent .cpp file
#include <iostream>
#include <winsock2.h>

using namespace std;
class SocketManager
{
private:
   WSADATA wsaData;
public:
   void setUpWINSOCK()
   {
      int result = WSAStartup( MAKEWORD( 2, 2 ), & wsaData );
      if( result != NO_ERROR )
         cout<<"Initialization error.\n"<<endl;
   }
   SocketManager(int = 27015, string = "127.0.0.1");
};

Im aware that im probably messing up something very basic, but i have no idea how to even search for this. Im new to Cpp, and even if i know Java
its not helping with this kind of errors. Also sorry for my english, im not used to using it in written form. I have never asked any question before on any other forum. Thats why im asking for patience :)
All help and links appreciated.

A:

WSAStartup@8 is a C++ mangled name. But the winsock library exports a C function WSAStartup. You have somewhere defined a prototype of WSAStartup before (or instead) including the "winsock.h" or "winsock2.h" header file.
Removing that wrong prototype will solve this linker problem.
Further make sure that you link with ws2_32.lib.

