如标题所述,我发生了一个段错误,我不明白为什么。我可以挖掘的最接近可能相关的问题是this。我的系统规格如下:
使用g ++进行编译时似乎没有问题。
我已将问题隔离到相对较小的代码片段中:
#include <iostream>
#include <cstdio>
#include <vector>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <string>
#include <fstream>
using namespace std;
int main()
{
cout << "Testing ... ";
vector<int> outVect(10);
// Save the data
std::ofstream outputFile_("archive.txt");
outputFile_ << std::scientific;
boost::archive::text_oarchive textOutArchive_(outputFile_);
cout << "chk1" << endl;
textOutArchive_ & BOOST_SERIALIZATION_NVP(outVect);
cout << "chk2" << endl;
return 0;
}
我正在编译:
icpc -g -static -openmp standalone.cc -o minimal -lboost_serialization ; ./minimal
有什么想法吗?
Valgrind给了我以下内容:
Testing ... chk1
==24519== Jump to the invalid address stated on the next line
==24519== at 0x0: ???
==24519== by 0x403100: boost::serialization::detail::extended_type_info_typeid_1<std::vector<int, std::allocator<int> > const>::get_instance() (extended_type_info_typeid.hpp:96)
==24519== by 0x4027C0: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::oserializer() (oserializer.hpp:106)
==24519== by 0x402934: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::instantiate() (oserializer.hpp:135)
==24519== by 0x402764: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_standard::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:264)
==24519== by 0x4027AA: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_conditional::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:273)
==24519== by 0x40274A: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:322)
==24519== by 0x40364E: void boost::archive::save<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:536)
==24519== by 0x401A85: void boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&, int) (basic_text_oarchive.hpp:78)
==24519== by 0x4021D5: boost::archive::text_oarchive& boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&) (interface_oarchive.hpp:78)
==24519== by 0x402E49: void boost::serialization::nvp<std::vector<int, std::allocator<int> > >::save<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int) const (nvp.hpp:77)
==24519== by 0x402C9E: void boost::serialization::access::member_save<boost::archive::text_oarchive, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const>(boost::archive::text_oarchive&, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const&, unsigned int) (access.hpp:93)
==24519== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==24519==
==24519==
==24519== Process terminating with default action of signal 11 (SIGSEGV)
==24519== Bad permissions for mapped region at address 0x0
==24519== at 0x0: ???
==24519== by 0x403100: boost::serialization::detail::extended_type_info_typeid_1<std::vector<int, std::allocator<int> > const>::get_instance() (extended_type_info_typeid.hpp:96)
==24519== by 0x4027C0: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::oserializer() (oserializer.hpp:106)
==24519== by 0x402934: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::instantiate() (oserializer.hpp:135)
==24519== by 0x402764: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_standard::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:264)
==24519== by 0x4027AA: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_conditional::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:273)
==24519== by 0x40274A: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:322)
==24519== by 0x40364E: void boost::archive::save<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:536)
==24519== by 0x401A85: void boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&, int) (basic_text_oarchive.hpp:78)
==24519== by 0x4021D5: boost::archive::text_oarchive& boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&) (interface_oarchive.hpp:78)
==24519== by 0x402E49: void boost::serialization::nvp<std::vector<int, std::allocator<int> > >::save<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int) const (nvp.hpp:77)
==24519== by 0x402C9E: void boost::serialization::access::member_save<boost::archive::text_oarchive, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const>(boost::archive::text_oarchive&, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const&, unsigned int) (access.hpp:93)
==24519==
答案 0 :(得分:0)
长评:
静态链接pthreads
(由OpenMP运行时使用)永远无法正常工作,除非链接了整个libpthreads.a
存档。要解决此问题,您应该将-Wl,--whole-archive -lpthreads -Wl,--no-whole-archive
附加到编译选项。
但是,我发现代码中没有并行区域,因此激活OpenMP是多余的。此外,看起来更像是RTTI因icpc而失败,因为错误发生在某些内容中,从extended_type_info_typeid.hpp
内部调用。