Snow Leopard Xcode破解了C ++ Debug版本 [英] C++ Debug builds broke in Snow Leopard Xcode

查看:80
本文介绍了Snow Leopard Xcode破解了C ++ Debug版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到Xcode 3.2和Snow Leopard之后,我的调试版本被破坏并且在运行时失败。 Stringstreams似乎不起作用。它们以发布模式工作。



我将它缩小为GCC 4.2,OSX SDK 10.6和_GLIBCXX_DEBUG预处理器符号的组合。这些是新Xcode项目调试配置的默认值。



这段代码显示了这个问题:

  #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);
试试{
stream<< 11; //<不按预期工作(见输出)
} catch(std :: bad_cast& e){
std :: cout<< 意外的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<< 期望:<< 11<<的std :: ENDL;
std :: cout<< 实际:<< stream.str()<<的std :: ENDL;

std :: cout<< std :: endl<< 完成<<的std :: ENDL;
返回0;
}

串流插入应该可以工作,但是当使用GCC 4.2和_GLIBCXX_DEBUG时, <<'运算符抛出异常,并设置坏的和失败的位。

我试过了以下结果的编译器和SDK的各种组合:
- 在SDK 10.6中使用GCC 4.2,LLVM-GCC或CLANG不起作用。
- 使用GCC 4.2,LLVM-GCC或CLANG与SDK 10.5一起工作。
- 在SDK 10.5或10.6中使用GCC 4.0。



如果_GLIBCXX_DEBUG被破坏或不被支持(使用SDK 10.6和GCC 4.2)这是新项目(C ++命令行)中调试配置的默认值?解析方案

在gcc 4.2中不支持STL调试模式这次。您可以在STL调试模式下使用gcc 4.0,或从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.

这篇关于Snow Leopard Xcode破解了C ++ Debug版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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