gpt4 book ai didi

mingw - "cc1plus.exe has stopped working"编译 Boost Spirit 代码时

转载 作者:行者123 更新时间:2023-12-04 20:54:02 29 4
gpt4 key购买 nike

我在尝试在 Windows Vista Home Premium 64 位下使用最新版本的 MinGW (GCC 4.5.2) 编译一些代码时遇到了一些奇怪的问题。编译此文件时,我收到一条消息“cc1plus.exe 已停止工作”,并且编译失败且没有错误消息。我试图将文件剥离到仍然会产生问题的绝对最低限度:

#include <boost/spirit/include/classic_file_iterator.hpp>
#include <boost/spirit/include/classic_position_iterator.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/qi.hpp>
#include <vector>

#define BOOST_SPIRIT_AUTO(domain_, name, expr) \
typedef boost::proto::result_of:: \
deep_copy<BOOST_TYPEOF(expr)>::type name##_expr_type; \
BOOST_SPIRIT_ASSERT_MATCH( \
boost::spirit::domain_::domain, name##_expr_type); \
BOOST_AUTO(name, boost::proto::deep_copy(expr)); \

using namespace std;

//This structure is used to determine the situation in which a certain tile sprite is used.
struct TileCase {
//A vector of bit fields for which adjacent tiles which must be filled.
vector<unsigned> filled;

//A vector of bit fields for which adjacent tiles are optionally filled.
vector<unsigned> optionalFilled;

TileCase() : filled(0),
optionalFilled(0){}
};

//Adapt the TileCase struct to a Fusion tuple.
BOOST_FUSION_ADAPT_STRUCT (
TileCase,
(std::vector<unsigned>, filled)
(std::vector<unsigned>, optionalFilled)
)

namespace qi = boost::spirit::qi;
namespace phoenix = boost::phoenix;
namespace ascii = boost::spirit::ascii;
using phoenix::function;
using ascii::space;
using ascii::char_;
using qi::eol;

//A skipper rule for comments.
BOOST_SPIRIT_AUTO(qi, comment, ("/*" >> *(char_ - "*/") >> "*/")
| ascii::space
| ("//" >> *(char_ - eol) >> eol)
);

//The Spirit error handler.
struct error_handler_ {
template<typename, typename, typename>
struct result { typedef void type; };

template <typename Iterator>
void operator()(
qi::info const& what,
Iterator err_pos, Iterator last) const
{
//Get the line position.
boost::spirit::classic::file_position_base<string> const& pos = err_pos.get_position();

//Throw an error.
stringstream error;
error << "Error! Expecting "
<< what
<< " at line "
<< pos.line
<< ", column "
<< pos.column
<< "!";
throw(runtime_error(error.str()));
}
};

function<error_handler_> const error_handler = error_handler_();

//The Spirit grammar for parsing tile data.
template<typename Iterator>
struct tileData : qi::grammar<Iterator, vector<TileCase>(), comment_expr_type> {
//The rule called when the parsing starts.
qi::rule<Iterator, vector<TileCase>(), comment_expr_type> start;

//The rule for parsing a single tile case.
qi::rule<Iterator, TileCase(), qi::locals<unsigned>, comment_expr_type> tile;

//The rule which parses yes/no/either bitflag blocks.
//Takes two references to unsigned, the first being the yes/no flag and the second being the optional flag.
qi::rule<Iterator, void(unsigned&, unsigned&), qi::locals<unsigned>, comment_expr_type> condBlock;

tileData() : tileData::base_type(start) {
using qi::eps;
using qi::lit;
using qi::on_error;
using qi::fail;
using qi::uint_;
using phoenix::at_c;
using phoenix::push_back;
using phoenix::resize;
using namespace qi::labels;

start = *tile[push_back(_val, _1)];

tile =
//Parse the filled definition.
lit("filled")

> '('
//Parse the generation to check for fills.
> uint_
[
_a = _1,
resize(at_c<0>(_val), _1 + 1),
resize(at_c<1>(_val), _1 + 1)
]
> ')'
//Opening curly bracket for filled definition.
> '{'
//The condition block.
> condBlock
(
//This one goes to filled[_a],
(at_c<0>(_val))[_a],
//and optionalFilled[_a].
(at_c<1>(_val))[_a]
)
//Closing curly bracket for filled definition.
> '}'
;

condBlock =
eps
[_a = 1]
>>
(
* (
(
+lit('+')
[_r1 += _a, _a *= 2]
)
|
(
+lit('*')
[_r2 += _a, _a *= 2]
)
|
(
+lit('-')
[_a *= 2]
)
)
)
;

on_error<fail>
(
start,
error_handler(_4, _3, _2)
);
}
};


int main() {
try {
//Set up the file iterator.
typedef char char_type;
typedef boost::spirit::classic::file_iterator<char_type> iterator_type;

//Open the file.
iterator_type first("Test.txt");

//Make sure the file is open.
if (!first) throw(runtime_error("Failed to open file!"));

//Find the end of the file.
iterator_type last = first.make_end();

//Wrap the file iterator with a position iterator.
typedef boost::spirit::classic::position_iterator2<iterator_type> pos_iterator_type;
typedef tileData<pos_iterator_type> tileData;
pos_iterator_type pos_first(first, last, "Test.txt");
pos_iterator_type pos_last;

//Prepare parsing information.
tileData tileData_parser;
vector<TileCase> cases;

//Parse the file.
if (phrase_parse(pos_first, pos_last, tileData_parser, comment, cases) && pos_first == pos_last) {
//Do something...
}
}
catch (const exception& e) {
cerr << "Exception while reading file:\n" << e.what() << endl;
return 1;
}

return 0;
}

在这个精简版中,编译器只有在启用调试符号 (-g) 时才会崩溃。但是,对于该文件的完整版本,它无论如何都会崩溃。同样,如果删除了 Spirit 代码的一部分(例如错误处理程序或注释跳过程序),它也会正确编译。这向我表明编译器内存不足,但我不完全确定如何修复它。

我曾尝试直接从命令行以及从 Code::Blocks 中构建,但 cc1plus 仍然崩溃。我启用的唯一编译器标志是 -g。我已经仔细检查了我只有一个 MinGW 安装,我已经尝试重新安装它,但问题仍然存在。什么会导致这种情况发生?

最佳答案

这是 gcc/MingW 的一个已知问题,但我不知道状态是什么(它是否已经被转载等) Spirit 邮件列表上的某个人提出了一个补丁,增加了 cc1plus.exe 的默认堆栈大小,据报道解决了这个问题。不过我自己没试过。

关于mingw - "cc1plus.exe has stopped working"编译 Boost Spirit 代码时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6811240/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com