Answer the question
In order to leave comments, you need to log in
How to fix linker error?
Hello everyone, I can not understand what the linker wants from me.
In short, there is a class that is described
class ModuleClass
{
public:
ModuleClass(const char* ModuleGUID);
ModuleClass(std::string ModuleGUID);
std::string GetModuleGUID();
int ProcessTast(TaskClass t);
~ModuleClass();
private:
int Start(TaskClass t);
int Stop();
int Extract();
int SetExec();
int Launch();
int AnswersProcessor();
int ReadingThreadChecker();
std::string ModuleGUID;
std::atomic<bool> isStarted;
std::atomic<bool> stopFlag;
PipeServerClass* pipe;
MessageCollectorClass* msgCollector;
std::thread * AnswerProcessingThread;
std::thread * ReaderCheckingThread;
};
./obj/local/arm64-v8a/objs-debug/Kernel/main.o: In function `void std::_Destroy<ModuleClass>(ModuleClass*)':
/home/drem1lin/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/stl_construct.h:93: undefined reference to `ModuleClass::~ModuleClass()'
./obj/local/arm64-v8a/objs-debug/Kernel/main.o: In function `void std::_Destroy<TaskClass>(TaskClass*)':
/home/drem1lin/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/stl_construct.h:93: undefined reference to `TaskClass::~TaskClass()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ModuleClass::ModuleClass(std::string ModuleGUID)
{
this->ModuleGUID.clear();
this->ModuleGUID.append(ModuleGUID);
msgCollector = new MessageCollectorClass();
std::string myfifo("//data//local//tmp//\0");
myfifo.append(this->ModuleGUID);
pipe = new PipeServerClass(myfifo, std::bind(std::mem_fn(&MessageCollectorClass::AddData), msgCollector, std::placeholders::_1, std::placeholders::_2));;
isStarted = false;
stopFlag = false;
ReaderCheckingThread = nullptr;
AnswerProcessingThread = nullptr;
}
Answer the question
In order to leave comments, you need to log in
The linker does not see the destructor because it is not implemented.
Just wrap all pointers in std::unique_ptr, the destructor will be generated automatically, and other problems will be reduced.
class ModuleClass
{
public:
ModuleClass(const char* ModuleGUID);
ModuleClass(std::string ModuleGUID);
std::string GetModuleGUID();
int ProcessTast(TaskClass t);
~ModuleClass() = default; // генерируется автоматически благодаря умным указателям
private:
int Start(TaskClass t);
int Stop();
int Extract();
int SetExec();
int Launch();
int AnswersProcessor();
int ReadingThreadChecker();
std::string ModuleGUID;
std::atomic<bool> isStarted;
std::atomic<bool> stopFlag;
std::unique_ptr<PipeServerClass> pipe;
std::unique_ptr<MessageCollectorClass> msgCollector;
std::unique_ptr<std::thread> AnswerProcessingThread;
std::unique_ptr<std::thread> ReaderCheckingThread;
};
detach
. In any case, you must either use a custom deleter for unique_ptr or implement a special wrapper over the stream.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question