gpt4 book ai didi

iphone - 如何在 ubuntu 中编译 Objective C 代码

转载 作者:太空宇宙 更新时间:2023-11-03 16:50:00 31 4
gpt4 key购买 nike

我是 Iphone 编程的初学者。我正在尝试编译 (ubuntu)。

#import <Foundation/Foundation.h>

int main (void)
{
NSLog (@"Executing");
return 0;
}

我编译了但是出现了如下错误

   subhash@subhash-Lenovo-G570:~/grit/iphone/mac$ gcc -lgnustep-base -lpthread -lob
jc -lm -I/usr/local/include/GNUstep -I/usr/include/GNUstep -fconstant-string-cla
ss=NSConstantString hello.m -o hello
In file included from /usr/include/GNUstep/Foundation/NSClassDescription.h:30:0,
from /usr/include/GNUstep/Foundation/Foundation.h:50,
from hello.m:1:
/usr/include/GNUstep/Foundation/NSException.h:42:2: error: #error The current se
tting for native-objc-exceptions does not match that of gnustep-base ... please
correct this.

我关注了 http://ubuntuforums.org/showthread.php?p=5593608作为引用。

我评论了 NSException.h 的#error 指令,问题就解决了。现在我收到新错误。

/tmp/ccQlI9wJ.o: In function `main':
hello.m:(.text+0x11): undefined reference to `NSLog'
/tmp/ccQlI9wJ.o: In function `__objc_gnu_init':
hello.m:(.text+0x2a): undefined reference to `__objc_exec_class'
/tmp/ccQlI9wJ.o:(.data+0x40): undefined reference to `__objc_class_name_NSConsta
ntString'
collect2: ld returned 1 exit status

最佳答案

Compile Objective-C Programs Using gcc有以下内容

Also note that if you did not include -D_NATIVE_OBJC_EXCEPTIONS, youmay run into the following error:

/usr/include/GNUstep/Foundation/NSException.h:42:2: error: #error The
current setting for native-objc-exceptions does not match that of
gnustep-base ... please correct this.

我遇到了与原始发布者相同的错误,传递 -D_NATIVE_OBJC_EXCEPTIONS 标志为我解决了这个问题。我试图做一些非常不标准的事情,所以它可能并不适合所有人。

请注意,shalki 的回答也可能解决该问题。如果那里引用的链接消失了,有问题的博客文章, Compile Objective-C Programs on Linux是中文或日文之类的,所以我不知道它到底在说什么,但我认为结果是通过

`gnustep-config --objc-flags`

作为 gcc 的参数。帖子有

gcc `gnustep-config --objc-flags` hello.m -o hello -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ -lgnustep-base

最后。现在,在我的机器上,gnustep-config --objc-flags 扩展为

-MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -D_REENTRANT -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -O2 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -fgnu-runtime -fconstant-string-class=NSConstantString -I. -I/home/faheem/GNUstep/Library/Headers -I/usr/local/include/GNUstep -I/usr/include/GNUstep

你好。请注意,此标志列表确实包含-D_NATIVE_OBJC_EXCEPTIONS,以及许多其他内容。作为记录,我的机器正在运行 Debian squeeze。这可能是 Debian/Ubuntu 特定的问题。我不确定。

关于iphone - 如何在 ubuntu 中编译 Objective C 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11358000/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com