Quando tó tentando compilar uma singleton
eu obtenho sempre a seguinte mensagem de retorno:
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: na função_start': (.text+0x20): referência indefinida para
main' Connection.o: na funçãoConnection::Connection()': /home/orion/Documentos/Workspace/AngoritmoTCC/Aplicacao-Tcc-Refazer/Connection.cpp:16: referência indefinida para
vtable for Connection' Connection.o: na funçãoConnection::getInstance()': /home/orion/Documentos/Workspace/AngoritmoTCC/Aplicacao-Tcc-Refazer/Connection.cpp:20: referência indefinida para
Connection::sinstance' /home/orion/Documentos/Workspace/AngoritmoTCC/Aplicacao-Tcc-Refazer/Connection.cpp:21: referência indefinida paraoperator new(unsigned long)' /home/orion/Documentos/Workspace/AngoritmoTCC/Aplicacao-Tcc-Refazer/Connection.cpp:21: referência indefinida para
Connection::sinstance' /home/orion/Documentos/Workspace/AngoritmoTCC/Aplicacao-Tcc-Refazer/Connection.cpp:22: referência indefinida paraConnection::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): referência indefinida para `__gxx_personality_v0' collect2: error: ld returned 1 exit status : recipe for target 'Connection' failed make: *** [Connection] Error 1
Desta forma, não consigo compilar, e preciso transformar em um arquivo .so, para rodar usando uma biblioteca. alguem pode me ajudar?
Editado
Arquivo Connection.cpp
Connection::Connection() {
}
static Connection *Connection::getInstance() {
if (!Connection::sinstance)
Connection::sinstance = new Connection();
return Connection::sinstance;
}
Arquivo Connection.h
#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*