在Mac OS X Snow Leopard的Xcode 3.2.1中,我打开了一个项目:C++ stdc ++类型的命令行工具.我有以下简单的代码:
#include <iostream>
#include <string>
using namespace std;
int main(){
string myvar;
cout << "Enter something: " << endl;
cin >> myvar;
cout << endl << myvar << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
该程序编译良好,并提示我"输入东西".当我输入内容,然后按回车键时,我收到以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
在另一台计算机上编译早期版本的Xcode(3.1.2)时(使用'命令行实用程序'选项打开项目,3.2.1中不存在),代码运行时没有问题.
有人知道发生了什么吗?谢谢,Yuval
据我所知,我没有在发布模式中遇到此问题x86_64.但我在Debug中看到了这个问题x86_64.如果我按照霍华德在这篇文章中给出的指示,我可以让它在调试模式下运行:
_GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1构建并运行,你会注意到它的工作原理.另一个有趣的观察是单独使用__gnu_debug::string(来自<debug/string>标题)不会触发错误.
编辑:来自马口(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/Project Templates/Application/Command Line Tool/C++ Tool/C++Tool.xcodeproj/并编辑project.pbxproj和删除第138行周围的线来为所有项目执行此操作:
"_GLIBCXX_DEBUG=1",
"_GLIBCXX_DEBUG_PEDANTIC=1",
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5763 次 |
| 最近记录: |