P
P
Pavel Kaptur2017-05-13 16:08:52
linux
Pavel Kaptur, 2017-05-13 16:08:52

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

So
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;
};

Если коротко, то есть модули, и этот класс должен представлять собой некий общий интерфейс к разным модулям.
В нем есть два потока - один проверяет состояние потока чтения PipeClass(он может загнуться, но модуль как бы будет активным), а второй обрабатывает ответы модуля.

So, for all this, the necessary wrappers are written, but when assembling, I get some kind of swearing that I don’t understand
./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)

Can you please explain what he wants?
And in general, I don’t understand a little if there is such a constructor
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;
}

What should be the destructor?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ariox41, 2017-05-13
@Ariox41

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;
};

UPD:
Although there can be problems with threads, you need to either wait for them to complete or call 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 question

Ask a Question

731 491 924 answers to any question