0

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?

Ilya
  • 4,583
  • 4
  • 26
  • 51
Роман Коптев
  • 1,555
  • 1
  • 13
  • 35
  • Different c++11 status of boost and your program? – n. m. could be an AI Sep 25 '15 at 08:10
  • Could you send us exact command line you used for compiling your program? – jnbrq -Canberk Sönmez Sep 25 '15 at 11:22
  • @jnbrq The command line is like: g++ -Wall -std=c++14 -g -c main.cpp -o main.o g++ -o test main.o -lboost_system -lboost_serialization -lboost_locale – Роман Коптев Sep 25 '15 at 16:32
  • @n.m. I have segmentation fault if I compile the code as c++11, c++14 and c++98 too – Роман Коптев Sep 25 '15 at 16:34
  • Woow! That's interesting. I have used the same command line, same boost as yours and everything same without any problem. Could you send the compiled versions of your boost and include files to me, or should we make some kind of remote debugging? – jnbrq -Canberk Sönmez Sep 25 '15 at 16:58
  • Or maybe this is a bug in standard library? My g++ version is 4.9.2, what's yours? – jnbrq -Canberk Sönmez Sep 25 '15 at 17:01
  • @jnbrq I had to say, the boost was compiled with gcc 5.1.0 from ppa:ubuntu-toolchain-r/ppa or ppa:ubuntu-toolchain-r/test, and, as I understand, uses 5.1.0 standard headers any way. Trying to compile the program (only) with g++ 4.8.5 alternative I had the same segfault, with clang I had compilation error in gcc 5.1.0 header files, included from /usr/include/boost/config.hpp (no member named 'max_align_t' in the global namespace). My source and compiled boost files in current state are at https://yadi.sk/d/AZ2-nPrzjLAgv. – Роман Коптев Sep 26 '15 at 09:33
  • Possibly, the problem is mainly using incompatible compilers using for boost and your program. – jnbrq -Canberk Sönmez Sep 26 '15 at 09:40
  • Can you rebuild boost using 4.8.5 or compile your program using 5.1.0? – jnbrq -Canberk Sönmez Sep 26 '15 at 09:41
  • @jnbrq I used 5.1.0 both for boost and the program. I'll try recompile boost with 4.8.5, but it seams it even doesn't understand option -std=c++14 I need – Роман Коптев Sep 26 '15 at 09:56
  • @РоманКоптев The error message you have posted, was it generated by the executable compiled with g++ 5.1.0? I ask this because the error message contains references to source files of g++ 4.8? – jnbrq -Canberk Sönmez Sep 26 '15 at 10:01
  • @jnbrq I don't know why it contains references of 4.8. Firstly I was used only gcc 5.1.0 for program and boost. And now I'v recompiled boost with 4.8.5 and was trying it with different compilers c++98, 11 and 14. gcc 4.8.5 doesn't support -std=c++14. All combinations have the segfault. clang compiles program with 8.5 boost, but has segfault in runtime too. I change alternatives for gcc with update-alternatives for gcc and g++. Why it can mix 4.8 headers in 5.1.0 buildings? – Роман Коптев Sep 26 '15 at 11:13
  • Maybe it's a bug of g++? Or update alternatives forgot changing include directories. Please execute the following command: `g++-5.1 -E -x c++ - -v < /dev/null` look at: http://stackoverflow.com/questions/11946294/dump-include-paths-from-g – jnbrq -Canberk Sönmez Sep 26 '15 at 11:21
  • The first path in output for g++ is /usr/include/c++/5 and nothing for 4.8. The error message shown in post is by gdb. – Роман Коптев Sep 26 '15 at 11:54
  • It works perfectly correct if I don't use -lboost_serialization and link directly with /usr/lib/libboost_serialization.so – Роман Коптев Sep 26 '15 at 12:13
  • Check whether boost is installed from the repositories. Maybe, the compiler is confused with that? – jnbrq -Canberk Sönmez Sep 26 '15 at 13:05

1 Answers1

1

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, e.g. use /usr/lib/libboost_serialization.so or /usr/lib/libboost_serialization.a and not -lboost_serialization linker options.

Thanks to all for help.

Роман Коптев
  • 1,555
  • 1
  • 13
  • 35