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.