0
When I’m 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/Application-Tcc-Redo/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/Application-Tcc-Redo/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
This way, I can’t compile, and I need to turn it into a file. So, 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;
}
File 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*
I can pass the code if you like, but they are simple, a Singleton to be used in the player/Stage for robotic simulation. That is, the code is just this, a file . the to be reunited with others of the same extension in a file . Being passed to the player to serve as a system controller. If you can help me with the solution, I appreciate it. There is nothing special, really, it is only the Singleton same, it is to represent inside the simulation the communication that we would have through radio waves.
– Andersoney Rodrigues
So it has no function
main
?– Jefferson Quesado
It is in this repository https://github.com/andersoney/AlgoritmoNovo.git
– Andersoney Rodrigues
No, it’s a extern "C". that’s called by the Stage.
– Andersoney Rodrigues
Sorry, to compile you will need to install the Stage pq needs the library of it. I can provide the code, but the installation, I do not know how to help because it varies from system to system.
– Andersoney Rodrigues
Here’s how to ask a question with a minimal, verifiable and complete example: https://answall.com/help/mcve; minimum means you’ll have what it takes to reproduce your problem, verifiable means that others will be able to verify what happened and complete means that it has no external dependency, it is all in the example provided next to the question.
– Jefferson Quesado
to check is simple. Comments extern "C" and uses a main in place.
– Andersoney Rodrigues
I’ll raise the example like this.
– Andersoney Rodrigues
@Andersoneyrodrigues , your question remains the same. Improve it with a mcve
– Jefferson Quesado
Ready. I put examples
– Andersoney Rodrigues