Why boost :: shared_ptr cannot be compiled if BOOST_NO_EXCEPTIONS is defined in user.hpp

I have an embedded system and you want to use boost on this system, but you need to disable the exception because I don't want to pay the cost of the exception.

The enhancement was provided by one user.hpp and the custom macro macro option BOOST_NO_EXCEPTIONS and BOOST_NO_EXCEPTION_STD_NAMESPACE , but the enhancement :: shared_ptr cannot be compiled (more precisely, cannot be connected) if these two macros are defined.

shared_ptr_boost.cpp:(.text._ZN5boost6detail12shared_countC2IiEEPT_[_ZN5boost6detail12shared_countC5IiEEPT_]+0x7a): undefined reference to `boost::throw_exception(std::exception const&)'
collect2: error: ld returned 1 exit status

why does boost give macro parameters, but does not promise to compile with these parameters?

+4
source share
2 answers

.

.

, BOOST_NO_EXCEPTIONS, boost::throw_exception(std::exception const&) -, .

throw_exception.hpp:

namespace boost
{

#ifdef BOOST_NO_EXCEPTIONS

void throw_exception(std::exception const & e); // user defined

#else

//[Not user defined --Dynguss]
template<class E> inline void throw_exception(E const & e)  
{
    throw e;
}

#endif

} // namespace boost
+9

.

shared_ptr_boost.cpp:

#include <boost/shared_ptr.hpp>
#include <stdio.h>
#include <exception>

namespace boost{
  void throw_exception(std::exception const &e){}
}
int main(){
  boost::shared_ptr<int> pName(new int(2));
  *pName += 3;
  printf("name = %d\n", *pName);
  return 0;
}

:

arm-hisiv100-linux-uclibcgnueabi-g++ -I../boost_1_59_0/ -DBOOST_NO_EXCEPTIONS -DBOOST_NO_EXCEPTION_STD_NAMESPACE -fno-exceptions shared_ptr_boost.cpp

1,7 ; .

-1

Source: https://habr.com/ru/post/1615520/


All Articles