unresolved external symbol boost::throw_exception

时间:2023-03-09 19:33:13
unresolved external symbol  boost::throw_exception

使用boost库,VS生成的时候一直报错,

error LNK2019: 无法解析的外部符号 "void __cdecl boost::throw_exception(class std::exception const &)"

搜索网上资料得知,可能是使用的boost库默认定义了BOOST_NO_EXCEPTIONS宏,需要用户自定义throw_exception函数,在报错的那个cpp中添加如下函数

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

结果还是一直报错,然后添加各种预定宏也解决不了。

后来查看<boost\throw_exception.hpp>发现,应该使用namespace boost

namespace boost
{
#ifdef BOOST_NO_EXCEPTIONS void throw_exception( std::exception const & e ); // user defined #else
//省略若干
#endif
} // namespace boost

在报错的那个cpp中添加如下函数后解决

namespace boost
{
void throw_exception(std::exception const & e) // user defined
{
return;
}
}

最后,感谢http://blog.****.net/is2120/article/details/6385304