fix: compile error when using libstdc++11 #163

Open
yushijinhun wants to merge 1 commits from yushijinhun/master into master
yushijinhun commented 2022-02-10 07:24:06 +01:00 (Migrated from github.com)

When compiling Livox-SDK with libstdc++11 and clang 15, I encounter the following error:

In file included from /home/user/repos/Livox-SDK/sdk_core/src/base/thread_base.cpp:25:
/home/user/repos/Livox-SDK/sdk_core/src/base/thread_base.h:46:8: error: no template named 'shared_ptr' in namespace 'std'
  std::shared_ptr<std::thread> thread_;
  ~~~~~^
/home/user/repos/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:18: error: no template named 'make_shared' in namespace 'std'; did you mean 'make_signed'?
  thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this);
            ~~~~~^~~~~~~~~~~
                 make_signed
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits:1911:12: note: 'make_signed' declared here
    struct make_signed
           ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits:1912:24: error: implicit instantiation of undefined template 'std::__make_signed_selector<std::thread, false, false>'
    { typedef typename __make_signed_selector<_Tp>::__type type; };
                       ^
/home/user/repos/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:13: note: in instantiation of template class 'std::make_signed<std::thread>' requested here
  thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this);
            ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits:1847:11: note: template is declared here
    class __make_signed_selector;
          ^

This PR fixes the problem by adding the missing <memory> header file.

When compiling Livox-SDK with libstdc++11 and clang 15, I encounter the following error: ``` In file included from /home/user/repos/Livox-SDK/sdk_core/src/base/thread_base.cpp:25: /home/user/repos/Livox-SDK/sdk_core/src/base/thread_base.h:46:8: error: no template named 'shared_ptr' in namespace 'std' std::shared_ptr<std::thread> thread_; ~~~~~^ /home/user/repos/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:18: error: no template named 'make_shared' in namespace 'std'; did you mean 'make_signed'? thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); ~~~~~^~~~~~~~~~~ make_signed /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits:1911:12: note: 'make_signed' declared here struct make_signed ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits:1912:24: error: implicit instantiation of undefined template 'std::__make_signed_selector<std::thread, false, false>' { typedef typename __make_signed_selector<_Tp>::__type type; }; ^ /home/user/repos/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:13: note: in instantiation of template class 'std::make_signed<std::thread>' requested here thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits:1847:11: note: template is declared here class __make_signed_selector; ^ ``` This PR fixes the problem by adding the missing `<memory>` header file.
myermo commented 2022-05-18 13:16:42 +02:00 (Migrated from github.com)

Why this error occurs? The compilation should be retro-compatible with older gcc versions, right?

Why this error occurs? The compilation should be retro-compatible with older gcc versions, right?
hollmmax commented 2022-08-03 13:33:43 +02:00 (Migrated from github.com)

Why this error occurs? The compilation should be retro-compatible with older gcc versions, right?

thread_base.h uses declarations from <memory> without explicitly including it. This does work on some C++ stdlib implementations which include <memory> inside of <thread>, but there's no reason for them to do that, so a newer version/different implementation causes this error.

> Why this error occurs? The compilation should be retro-compatible with older gcc versions, right? `thread_base.h` uses declarations from `<memory>` without explicitly including it. This does work on some C++ stdlib implementations which include `<memory>` inside of `<thread>`, but there's no reason for them to do that, so a newer version/different implementation causes this error.
sergii-koltsiuk commented 2022-08-31 17:49:11 +02:00 (Migrated from github.com)

Have the same problem with build. Apply this fix assap please.

Have the same problem with build. Apply this fix assap please.
DrTon commented 2022-11-09 00:02:04 +01:00 (Migrated from github.com)

The same here! Fix please!

The same here! Fix please!
This repo is archived. You cannot comment on pull requests.