简体   繁体   中英

boost::serialization segmentation fault

Trying compile any program using boost::serialization text or binary archive with string or file stream I have segmentation fault error. Even for the simple code like:

#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(...) {}
  }
}

Error:

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 installed on Ubuntu trusty as

./bootstrap.sh -prefix=/usr
sudo ./b2 install

Why it can be so?

After manual boost installation on ubuntu, program was linked with wrong libraries. There was another copy of boost, installed in /usr/lib/x86_64-linux-gnu directory, which had higher priority for linker. On Ubuntu default boost installations from repository are multiarch, 64 bit version for Intel processors is installed in /usr/lib/x86_64-linux-gnu and may be several versions for several architectures on the same machine.

As a variant of simple manual boost installation (actual for 1.59):

./bootstrap.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
sudo ./b2 install

bash shell commands from the boost unpacked source directory.

This will install boost in standard directories, used and by standard boost packages from repository. (And may be potentially may cause some conflicts with standard packages)

Or install boost in some directory and do it visible for linker with some standard way. Or link directly to the installed libraries, eg use /usr/lib/libboost_serialization.so or /usr/lib/libboost_serialization.a and not -lboost_serialization linker options.

Thanks to all for help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM