Xcode 3.2.1和C ++字符串失败! [英] Xcode 3.2.1 and C++ string fails!

查看:193
本文介绍了Xcode 3.2.1和C ++字符串失败!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS X Snow Leopard的Xcode 3.2.1中,我打开一个项目:
C ++ stdc ++类型的命令行工具。
我有以下简单代码:

In Xcode 3.2.1 on Mac OS X Snow Leopard, I open a project under: Command Line Tool of type C++ stdc++. I have the following simple code:

#include <iostream>
#include <string>

using namespace std;

int main(){
    string myvar;
        cout << "Enter something: " << endl;
    cin >> myvar;
    cout << endl << myvar << endl;
    return 0;
}

程序编译正常,并提示我输入Enter Something。当我输入的东西,然后按回车,我得到以下错误:

The program compiles fine, and prompts me to "Enter Something". When I type in something, and then press enter, I get the following error:

myproject(766) malloc: *** error for object 0x1000041c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal:  "SIGABRT".
sharedlibrary apply-load-rules all
(gdb)

在另一台计算机上打开较早版本的Xcode(3.1.2)(使用'command line utility'选项打开项目,这在3.2.1中不存在),代码运行时没有PROBLEM。

When compiling on an earlier version of Xcode (3.1.2) on a different computer (opened the project with the 'command line utility' option, which does not exist in 3.2.1), the code runs with NO PROBLEM.

有人知道发生了什么吗?
感谢,
Yuval

Does anybody know what's going on? Thanks, Yuval

推荐答案

据我所知,我没有遇到这个问题在 x86_64 的发布模式中。但我看到的问题在Debug x86_64 。如果我遵循Howard在本文中提供的说明,我可以获得它以调试模式运行:

As far as I can tell, I'm not experiencing this issue in Release mode for x86_64. But I am seeing the issue in Debug x86_64. If I follow the directions given by Howard in this post, I'm able to get it running in debug mode:


  1. 项目 - >编辑活动目标...


  2. 搜寻「预处理器」

  3. 删除 _GLIBCXX_DEBUG = 1 _GLIBCXX_DEBUG_PEDANTIC = 1 li>
  1. Project -> Edit Active Target ...
  2. Click Build tab
  3. Search for "preprocessor"
  4. Delete _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1

构建并运行,您会注意到它的工作原理。另一个有趣的发现是,使用 __ gnu_debug :: string (从< debug / string> 头)触发错误。

Build and run, you'll notice it works. Another interesting observation is that using __gnu_debug::string (from the <debug/string> header) alone does not trigger the error.

编辑:从马口( XCode 3.2.1中的已知问题

from the horses mouth (known issues in XCode 3.2.1)


默认的gcc 4.2编译器与标准C ++库调试模式不兼容。使用Xcode 3.2编译的C ++程序可能无法在Debug配置中工作。要修复此问题,请将编译器版本设置为4.0,或编辑调试配置的预处理器宏并删除条目:
_GLIBCXX_DEBUG = 1 _GLIBCXX_DEBUG_PEDANTIC = 1

您可以通过导航到 / Developer / Library / Xcode /项目模板/应用程序/命令行工具/ C ++ Tool / C ++ Tool.xcodeproj / 并编辑 project.pbxproj 并删除138行周围的行:

You can do this for all projects by navigating to /Developer/Library/Xcode/Project Templates/Application/Command Line Tool/C++ Tool/C++Tool.xcodeproj/ and editing project.pbxproj and deleting the lines around line 138:

"_GLIBCXX_DEBUG=1",
"_GLIBCXX_DEBUG_PEDANTIC=1",

这篇关于Xcode 3.2.1和C ++字符串失败!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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