I'm trying to create a singleton which wraps an shared library. But when I'm try to get the instance of class (from an static function) I'm getting the error "undefined referenced to NativeLibrary::Instance()".
NativeLibrary.h:
#ifndef NATIVELIBRARY_H_INCLUDED
#define NATIVELIBRARY_H_INCLUDED
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
using namespace std;
class NativeLibrary
{
#ifdef _WIN32
HINSTANCE handle;
#else
void* handle;
#endif // _WIN32
NativeLibrary();
~NativeLibrary();
private:
static NativeLibrary* _instance;
public:
static NativeLibrary* Instance();
};
#endif // NATIVELIBRARY_H_INCLUDED
NativeLibrary.cpp:
#include "NativeLibrary.h"
#include "NativeArray.h"
#ifdef _WIN32
#include <windows.h>
#define symLoad GetProcAddress GetProcAddress
#else
#include <dlfcn.h>
#define symLoad dlsym
#endif
NativeLibrary::_instance = NULL;
NativeLibrary::NativeLibrary()
{
#ifdef _WIN32
handle = LoadLibrary("NativeLibrary.dll");
#elif __APPLE__
handle = dlopen("NativeLibrary.dylib", RTLD_LAZY);
#else
handle = dlopen("NativeLibrary.so", RTLD_LAZY);
#endif // _WIN32
}
NativeLibrary::~NativeLibrary()
{
#ifdef _WIN32
FreeLibrary(handle);
#else
dlclose(handle);
#endif // _WIN32
}
NativeLibrary* NativeLibrary::Instance()
{
if(_instance != NULL)
_instance = new NativeLibrary();
return _instance;
}
main.cpp (where I'm trying to get the instance):
#include "NativeLibrary.h"
void main()
{
NativeLibrary* instanceLib = NativeLibrary::Instance();
}