![](/img/trans.png)
[英]CRASH: Segmentation fault: Boost serialization loading - calling constructor with null
[英]boost::serialization segmentation fault
嘗試使用boost::serialization
文本或帶有字符串或文件流的二進制歸檔文件編譯任何程序,我遇到分段錯誤錯誤。 即使對於簡單的代碼,例如:
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <sstream>
int main()
{
std::stringstream ss;
{
try
{
boost::archive::binary_oarchive oa(ss);
}
catch(...) {}
}
}
錯誤:
received signal SIGSEGV, Segmentation fault.
In ?? () ()
#1 0x00007ffff79ad770 in sputn (__n=8, __s=0x7fffffffd990 "\026", this=<optimized out>) at /usr/include/c++/4.8/streambuf:451
/usr/include/c++/4.8/streambuf:451:15915:beg:0x7ffff79ad770
At /usr/include/c++/4.8/streambuf:451
#1 0x00007ffff79ad770 in sputn (__n=8, __s=0x7fffffffd990 "\026", this=<optimized out>) at /usr/include/c++/4.8/streambuf:451
/usr/include/c++/4.8/streambuf:451:15915:beg:0x7ffff79ad770
Boost 1.59安裝在Ubuntu Trusty上
./bootstrap.sh -prefix=/usr
sudo ./b2 install
為什么會這樣呢?
在ubuntu上手動安裝Boost之后,程序與錯誤的庫鏈接。 在/ usr / lib / x86_64-linux-gnu目錄中安裝了boost的另一個副本,該副本的鏈接程序優先級更高。 在Ubuntu上,來自存儲庫的默認Boost安裝是多體系的,用於Intel處理器的64位版本安裝在/ usr / lib / x86_64-linux-gnu中,並且可能是同一台計算機上幾種體系結構的多個版本。
作為簡單的手動增強安裝的變體(實際適用於1.59):
./bootstrap.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
sudo ./b2 install
來自boost解壓縮源目錄的bash shell命令。
這會將boost安裝在標准目錄中,並由存儲庫中的標准boost軟件包使用和安裝。 (並且可能潛在地導致與標准軟件包的某些沖突)
或在某些目錄中安裝boost,並以某種標准方式使其對鏈接器可見。 或直接鏈接到已安裝的庫,例如,使用/usr/lib/libboost_serialization.so或/usr/lib/libboost_serialization.a,而不使用-lboost_serialization鏈接器選項。
感謝大家的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.