T
thegreatgonzo
I have a little problem. Read this please:
//library.h
class myClass
{
public:
myClass();
static myClass *instance();
private:
static myClass *self;
};
//library.cpp
#include "library.h"
myClass::myClass()
{
self = this;
//more initialisation stuff
}
myClass *myClass::instance()
{
return self;
}
i compiled this 'library':
g++ -Wall -fPIC -c library.cpp -o library.o
g++ -Wall -shared -o libLibrary.so library.o
without any errors
then: i tried to use my 'library':
// main.cpp
#include "library.h"
int main()
{
myClass test;
// do something usefull with the test class
return 0;
}
that's it! but it won't compile! it gave the error:
g++ -lLibrary main.cpp -o test
libLibrary.so: undefined reference to myClass::self
collect2: ld returned 1 exit status
can anyone tell me what i am doing wrong? this isn't the real library,
that one is much bigger, but this is the part what is producing the error.
Regards,
Leon
//library.h
class myClass
{
public:
myClass();
static myClass *instance();
private:
static myClass *self;
};
//library.cpp
#include "library.h"
myClass::myClass()
{
self = this;
//more initialisation stuff
}
myClass *myClass::instance()
{
return self;
}
i compiled this 'library':
g++ -Wall -fPIC -c library.cpp -o library.o
g++ -Wall -shared -o libLibrary.so library.o
without any errors
then: i tried to use my 'library':
// main.cpp
#include "library.h"
int main()
{
myClass test;
// do something usefull with the test class
return 0;
}
that's it! but it won't compile! it gave the error:
g++ -lLibrary main.cpp -o test
libLibrary.so: undefined reference to myClass::self
collect2: ld returned 1 exit status
can anyone tell me what i am doing wrong? this isn't the real library,
that one is much bigger, but this is the part what is producing the error.
Regards,
Leon