glog编译报错解决

编译报错

centos9上编译glog0.3.4和0.3.5报错:

src/googletest.h:579:33: error: ISO C++17 does not allow dynamic exception specifications
  579 | void* operator new(size_t size) throw(std::bad_alloc) {
      |                                 ^~~~~
src/googletest.h:586:35: error: ISO C++17 does not allow dynamic exception specifications
  586 | void* operator new[](size_t size) throw(std::bad_alloc) {
      |                                   ^~~~~
src/logging_unittest.cc: In function ‘void TestDCHECK()’:
src/logging_unittest.cc:567:3: warning: ‘template<class> class std::auto_ptr’ is deprecated: use 'std::unique_ptr' instead [-Wdeprecated-declarations]
  567 |   auto_ptr<int64> sptr(new int64);
      |   ^~~~~~~~
In file included from /usr/include/c++/11/bits/locale_conv.h:41,
                 from /usr/include/c++/11/locale:43,
                 from /usr/include/c++/11/iomanip:43,
                 from src/logging_unittest.cc:44:
/usr/include/c++/11/bits/unique_ptr.h:57:28: note: declared here
   57 |   template<typename> class auto_ptr;
      |                            ^~~~~~~~
make: *** [Makefile:1275: src/logging_unittest-logging_unittest.o] Error 1

解决方法:

void* operator new(size_t size) throw(std::bad_alloc) {

改为

void* operator new(size_t size) {

即可;
或者根据最新的版本,将报错部分的2个函数修改为:

void* operator new(size_t size, const std::nothrow_t&) noexcept {
  if (google::g_new_hook) {
    google::g_new_hook();
  }
  return malloc(size);
}

void* operator new(size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
  void* p = ::operator new(size, std::nothrow);
  if (p == nullptr) {
    throw std::bad_alloc{};
  }
  return p;
}

void* operator new[](size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
  return ::operator new(size);
}

安装后使用报错

error while loading shared libraries: libglog.so.0: cannot open shared object file: No such file or ...

根据实际安装位置运行命令

sudo ldconfig /usr/local/lib
posted @ 2024-06-06 14:30  bitwoods  阅读(74)  评论(0编辑  收藏  举报