该计划创建了目标 c++正在崩溃

发布于 2024-12-08 10:21:04 字数 1352 浏览 0 评论 0原文

我正在开发一个应用程序来获取 Mac OS X 10.5 或更高版本中已安装软件的列表。该程序是使用 Objective-C++(c、c++、obj-c)创建的。每次我运行该程序时,它都会崩溃。

int main (int argc, const char * argv[])  
{
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    
     //My part of coding
     [pool drain];  // This is the crash prone place
     return 0; 
}

我在这里提供项目设置详细信息:

文件扩展名:.mm

编译为:objective c++

对象GC:不支持

使用的库:libxml2.2.dylib,基础框架

目标平台:x86_x64

开发:Mac OS X 10.6.8、Xcode 3.2.6

应用程序类型:控制台应用程序

我不'不知道需要设置任何其他选项来编译 Objective C++。任何有关此问题的帮助将不胜感激。

是的。我已经将基础 sdk 设置为 10.5

以下是日志跟踪:

调试器已退出,状态为 0。 [会话于 2011 年 10 月 3 日开始 22:29:25 +0530.] GNU gdb 6.3.50-20050815(Apple 版本 gdb-1515)(周六 1 月 15 日 08:33:48 UTC 2011) 版权所有 2004 自由软件基金会, Inc. GDB 是免费软件,受 GNU 通用公共许可证保护, 欢迎您对其进行更改和/或分发其副本 某些条件。输入“显示复制”以查看条件。那里 对GDB绝对没有任何保证。输入“显示保修”以了解详细信息。 该 GDB 被配置为“x86_64-apple-darwin”.tty /dev/ttys003 正在将程序加载到调试器中... 程序已加载。运行[切换到 进程2973]正在运行...程序收到信号:“EXC_BAD_ACCESS”。 共享库应用加载规则全部(gdb)

我还有一个问题。在c++类析构函数中释放obj-c对象是否有效? 像这样

myclass::myclasss() { myobjcinterface* myobjc = [[myobjcinterface 分配]初始化]; }

myclass::~myclass() { [myobjc 版本]; }

I am developing a application to get list of installed software in Mac OS X 10.5 or above. The program is created using objective-c++ (c,c++, obj-c). Every time I run the program, it is crashing.

int main (int argc, const char * argv[])  
{
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    
     //My part of coding
     [pool drain];  // This is the crash prone place
     return 0; 
}

Here I'm providing project setting details:

file extention: .mm

compiled as : objective c++

Objc GC : unsupported

libraries used : libxml2.2.dylib, Foundation Framework

target platfom: x86_x64

development: Mac OS X 10.6.8, Xcode 3.2.6

Application type: console application

I don't know any other option need to set to compile objective c++. Any help regarding this would be appreciated.

yes. I already set base sdk as 10.5

Here is the log trace:

The Debugger has exited with status 0. [Session started at 2011-10-03
22:29:25 +0530.] GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat
Jan 15 08:33:48 UTC 2011) Copyright 2004 Free Software Foundation,
Inc. GDB is free software, covered by the GNU General Public License,
and you are welcome to change it and/or distribute copies of it under
certain conditions. Type "show copying" to see the conditions. There
is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys003
Loading program into debugger… Program loaded. run [Switching to
process 2973] Running… Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all (gdb)

I have one more question. Is it valid to release the obj-c object in c++ class destructor?
like this

myclass::myclasss() { myobjcinterface* myobjc = [[myobjcinterface
alloc] init]; }

myclass::~myclass() { [myobjc release]; }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光礼记 2024-12-15 10:21:05

我还有一个问题。在c++类析构函数中释放obj-c对象是否有效?像这样

是的。

至于您的 EXC_BAD_ACCESS,如果它发生在自动释放池的耗尽上,则几乎可以肯定您已经自动释放了某些内容并释放了它,因此该池正在尝试释放悬空指针。

尝试将环境变量 NSZombieEnabled 设置为 YES,然后运行您的程序。它应该为您提供有关过度释放的诊断。

I have one more question. Is it valid to release the obj-c object in c++ class destructor? like this

Yes.

As for your EXC_BAD_ACCESS, if it's hapening on drain of an autorelease pool, it's almost certain that you have autoreleased something and released it, so the pool is trying to release a dangling pointer.

Try setting the environment variable NSZombieEnabled to YES and then running your program. It should give you diagnostics about over-releases.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文