When trying to compile a singleton
I always get the following return message:
g ++ -g -Wall
pkg-config --cflags stage
-fPICpkg-config --libs stage
-c -Wall Connection.cpp cc Connection.o -o Connection /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: in function_start': (.text+0x20): referência indefinida para
main ' Connection.o: in functionConnection::Connection()': /home/orion/Documentos/Workspace/AngoritmoTCC/Aplicacao-Tcc-Refazer/Connection.cpp:16: referência indefinida para
vtable for Connection ' Connection.o: in functionConnection::getInstance()': /home/orion/Documentos/Workspace/AngoritmoTCC/Aplicacao-Tcc-Refazer/Connection.cpp:20: referência indefinida para
Connection :: sinstance ' /home/orion/Documents/Workspace/AngoritmoTCC/Account-Tcc-Refazer/Connection.cpp:21: undefined reference tooperator new(unsigned long)' /home/orion/Documentos/Workspace/AngoritmoTCC/Aplicacao-Tcc-Refazer/Connection.cpp:21: referência indefinida para
Connection :: sinstance ' /home/orion/Documents/Workspace/AngoritmoTCC/Account-Tcc-Refacer/Connection.cpp:22: undefined reference toConnection::sinstance' /home/orion/Documentos/Workspace/AngoritmoTCC/Aplicacao-Tcc-Refazer/Connection.cpp:21: referência indefinida para
operator delete (void *, unsigned long) ' Connection.o :( data.DW.ref .__ gxx_personality_v0 [DW.ref .__ gxx_personality_v0] + 0x0): undefined reference to '__gxx_personality_v0' collect2: error: ld returned 1 exit status : recipe for target 'Connection' failed make: *** [Connection] Error 1
In this way, I can not compile, and need to transform into a .so file, to run using a library. Can someone help me?
Edited
Connection.cpp File
Connection::Connection() {
}
static Connection *Connection::getInstance() {
if (!Connection::sinstance)
Connection::sinstance = new Connection();
return Connection::sinstance;
}
Connection.h File
#ifndef CONNECTION_H
#define CONNECTION_H
class Connection {
public:
static Connection *getInstance();
Connection();
virtual ~Connection();
private:
static Connection *sinstance;
};
#endif /* CONNECTION_H */
Main.cpp
int main(){
ControllerPrincipal *controller = new ControllerPrincipal();
}
MaKeFIle
COMMON_DIR = ../common
run: all
all: coordination.so createScenario
createScenario: createScenario.cpp
$(CXX) createScenario.cpp -o createScenario
coordination.so: ControllerPrincipal.o main.o Connection
$(CXX) $(CXXFLAGS) $(LINKFLAGS) main.o ControllerPrincipal.o
Connection.o -o coordination.so -shared
ControllerPrincipal.o: ControllerPrincipal.cpp ControllerPrincipal.h
$(CXX) $(CXXFLAGS) $(LINKFLAGS) -c ControllerPrincipal.cpp
main.o: main.cpp
$(CXX) $(CXXFLAGS) $(LINKFLAGS) -c main.cpp
Connection.o: Connection.cpp Connection.h
$(CXX) $(CXXFLAGS) $(LINKFLAGS) -c -Wall Connection.cpp
clean:
@rm -f *.o *.so server createScenario
reset:
rm -rf nRobos*