加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Xcode 3.2.1和C字符串失败!

发布时间:2020-12-14 18:07:41 所属栏目:百科 来源:网络整理
导读:在Mac OS X Snow Leopard的 Xcode 3.2.1中,我打开一个项目: C stdc类型的命令行工具. 我有以下简单的代码: #include iostream#include stringusing namespace std;int main(){ string myvar; cout "Enter something: " endl; cin myvar; cout endl myvar e
在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,我可以让它在调试模式下运行:

>项目 – >编辑活动目标…
>单击构建选项卡
>搜索“预处理器”
>删除_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",

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读