I have the following problems while trying to implement the Singleton pattern in c++ :
- external symbol not resolved __imp_WSAStartup referenced in the function "private: __cdecl MaWinsock::MaWinsock(void)" (??0MaWinsock@@AEAA@XZ) )
- external symbol not resolved __imp_WSACleanup referenced in the function"public: __cdecl MaWinsock::~MaWinsock(void)" (??1MaWinsock@@QEAA@XZ)
Here is MaWinsock.h
#include <WinSock2.h>
class MaWinsock
{
WSADATA wsaData; // structure contenant les données de la librairie winsock à initialiser. représente la DLL.
MaWinsock(void);
static MaWinsock *instanceUnique;
public:
static MaWinsock *getInstance();
~MaWinsock(void);
};
Here is MaWinsock.cpp
#include <iostream>
#include "Exception.h"
#include "MaWinsock.h"
using namespace std;
/* static */ MaWinsock* MaWinsock::instanceUnique = NULL;
/* static */ MaWinsock* MaWinsock::getInstance()
{
if (!instanceUnique) instanceUnique = new MaWinsock;
return instanceUnique;
}
MaWinsock::MaWinsock(void)
{
int r;
r = WSAStartup(MAKEWORD(2, 0), &wsaData); // MAKEWORD(2,0) sert à indiquer la version de la librairie à utiliser : 1 pour winsock et 2 pour winsock2
/* en cas de succès, wsaData a été initialisée et l'appel a renvoyé la valeur 0 */
if (r) throw Exception("L'initialisation a échoué");
cout << "initialisation winsock effectuée" << endl;
}
MaWinsock::~MaWinsock(void)
{
WSACleanup();
cout << "libération des ressources de la winsock effectuée" << endl;
}
What is very strange is that on another related project this code works well but here,i can't figure out where the problem is.
If one of you is familiar with this pattern, any help would be appreciated.
Thank you