C ++ Debug构建在Snow Leopard X-Code中崩溃 [英] C++ Debug builds broke in Snow Leopard X-Code

查看:155
本文介绍了C ++ Debug构建在Snow Leopard X-Code中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到XCode 3.2和Snow Leopard后,我的调试版本已损坏,并在运行时失败。 Stringstreams似乎不工作。它们以释放模式工作。



我将其缩小到GCC 4.2,OSX SDK 10.6和_GLIBCXX_DEBUG预处理器符号的组合。这些是新的XCode项目的Debug配置的默认值。



此代码显示问题:

  #include< iostream> 
#include< string>
#include< sstream>

int main(int argc,char * const argv []){

std :: stringstream stream;
std :: cout<< 预期实际< std :: endl;
std :: cout<< stream.bad:0< stream.bad()<< std :: endl;
std :: cout<< stream.fail:0< stream.fail()<< std :: endl;
std :: cout<< stream.eof:0< stream.eof()<< std :: endl;
std :: cout<< stream.good:1< stream.good()<< std :: endl;

stream.exceptions(std :: ios :: badbit | std :: ios :: failbit | std :: ios :: eofbit);
try {
stream<< 11; //<不按预期工作(见输出)
} catch(std :: bad_cast& e){
std :: cout< Unexpected bad_cast:<< e.what()< std :: endl;
} catch(std :: exception& e){
std :: cout< 意外异常:< e.what()< std :: endl;
}

std :: cout<< 预期实际< std :: endl;
std :: cout<< stream.bad:0< stream.bad()<< std :: endl;
std :: cout<< stream.fail:0< stream.fail()<< std :: endl;
std :: cout<< stream.eof:0< stream.eof()<< std :: endl;
std :: cout<< stream.good:1< stream.good()<< std :: endl;
std :: cout<< std :: endl;
std :: cout<< EXPECT:<< 11<< std :: endl;
std :: cout<< ACTUAL:<< stream.str()<< std :: endl;

std :: cout<< std :: endl< 完成<< std :: endl;
return 0;字符串流插入应该可以工作,但是当使用GCC 4.2和_GLIBCXX_DEBUG时,'''' <<操作符抛出异常,并设置坏位和失败位。



我尝试过编译器和SDK的各种组合与这些结果:
- 使用GCC 4.2,LLVM-GCC或CLANG与SDK 10.6不工作。
- 使用GCC 4.2,LLVM-GCC或CLANG与SDK 10.5工作。
- 使用GCC 4.0与SDK 10.5或10.6工作原理。



如果_GLIBCXX_DEBUG破碎或不支持(与SDK 10.6和GCC 4.2)这是新项目(C ++命令行)中Debug配置的默认值?

解决方案

gcc 4.2不支持STL调试模式这次。您可以使用gcc 4.0与STL调试模式,或从您的Debug配置中删除调试模式预处理器宏,并继续使用gcc 4.2。


After upgrading to XCode 3.2 and Snow Leopard, my debug builds are broken and fail at runtime. Stringstreams do not seem to work. They work in Release mode.

I've narrowed it down to a combination of GCC 4.2, OSX SDK 10.6 and the _GLIBCXX_DEBUG pre-processor symbol. These are the defaults for new XCode projects' Debug configurations.

This code shows the problem:

#include <iostream>
#include <string>
#include <sstream>

int main (int argc, char * const argv[]) {

	std::stringstream stream;
	std::cout << "             expected  actual" << std::endl;
	std::cout << "stream.bad:  0         " << stream.bad() << std::endl;
	std::cout << "stream.fail: 0         " << stream.fail() << std::endl;
	std::cout << "stream.eof:  0         " << stream.eof() << std::endl;
	std::cout << "stream.good: 1         " << stream.good() << std::endl;

	stream.exceptions(std::ios::badbit | std::ios::failbit | std::ios::eofbit);
	try{
		stream << 11;       //< Does not work as expected (see output)
	}catch (std::bad_cast &e) {
		std::cout << "Unexpected bad_cast: " << e.what() << std::endl;
	}catch(std::exception &e){
		std::cout << "Unexpected exception: " << e.what() << std::endl;
	}

	std::cout << "             expected  actual" << std::endl;
	std::cout << "stream.bad:  0         " << stream.bad() << std::endl;
	std::cout << "stream.fail: 0         " << stream.fail() << std::endl;
	std::cout << "stream.eof:  0         " << stream.eof() << std::endl;
	std::cout << "stream.good: 1         " << stream.good() << std::endl;
	std::cout << std::endl;
	std::cout << "EXPECT: " << 11 << std::endl;
	std::cout << "ACTUAL: " << stream.str() << std::endl;

	std::cout << std::endl << "Done" << std::endl;
	return 0;
}

The stringstream insertion should work, but when using GCC 4.2 and _GLIBCXX_DEBUG, the '<<' operator throws an exception, and the bad and fail bits are set.

I've tried various combinations of compiler and SDK with these results: - Using GCC 4.2, LLVM-GCC, or CLANG with SDK 10.6 does NOT work. - Using GCC 4.2, LLVM-GCC, or CLANG with SDK 10.5 does work. - Using GCC 4.0 with either SDK 10.5 or 10.6 works.

If _GLIBCXX_DEBUG is broken or not supported (with SDK 10.6 and GCC 4.2), then why is this the default for Debug configurations in new projects (C++ command line)?

解决方案

STL debug mode is not supported in gcc 4.2 at this time. You can use gcc 4.0 with STL debug mode, or remove the debug mode preprocessor macros from your Debug configuration and keep using gcc 4.2.

这篇关于C ++ Debug构建在Snow Leopard X-Code中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆