Xcode 3.2.1和C字符串失败!
在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; } 该程序编译良好,并提示我“输入东西”.当我输入内容,然后按回车键时,我收到以下错误: 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中不存在),代码运行时没有问题. 有人知道发生了什么吗? 解决方法
据我所知,我在x86_64的发布模式下没有遇到此问题.但我在Debug x86_64中看到了这个问题.如果我按照
directions given by Howard in this post,我可以让它在调试模式下运行:
>项目 – >编辑活动目标… 构建并运行,你会注意到它的工作原理.另一个有趣的观察是,单独使用__gnu_debug :: string(来自< debug / string>标头)不会触发错误. 编辑:从马口(known issues in XCode 3.2.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", (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |