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; }
该程序编译良好,并提示我“输入东西”.当我输入内容,然后按回车键时,我收到以下错误:
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)时(使用’命令行实用程序’选项打开项目,3.2.1中不存在),代码运行时没有问题.
有人知道发生了什么吗?
谢谢,
尤瓦
解决方法
>项目 – >编辑活动目标…
>单击构建选项卡
>搜索“预处理器”
>删除_GLIBCXX_DEBUG = 1 _GLIBCXX_DEBUG_PEDANTIC = 1
构建并运行,你会注意到它的工作原理.另一个有趣的观察是,单独使用__gnu_debug :: string(来自< debug / string>标头)不会触发错误.
编辑:从马口(known issues in XCode 3.2.1)
The default gcc 4.2 compiler is not compatible with the Standard C++ Library Debug Mode. C++ programs compiled with Xcode 3.2 may not work in the Debug configuration. To fix this,set the Compiler Version to 4.0,or edit the Debug configuration’s Preprocessor Macros and remove the entries:
_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",