【问题标题】:How to compile Objective C code in ubuntu如何在 ubuntu 中编译 Objective C 代码
【发布时间】:2012-07-06 15:56:48
【问题描述】:

我是 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

【问题讨论】:

  • 我不得不在 NSException.h 中注释掉那个错误,没有其他工作。
  • 如何正确编译。
  • 这就是我刚刚写的。注释掉头文件中的#error指令。
  • 谢谢,问题已解决,但我遇到了新错误。
  • 我认为避免所有软件包并直接从主干安装 GNUstep 是一个更好的主意。并使用铿锵声。或者用这个lists.gnu.org/archive/html/discuss-gnustep/2012-10/…

标签: iphone ubuntu gnustep


【解决方案1】:

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

另外请注意,如果您没有包含 -D_NATIVE_OBJC_EXCEPTIONS,您 可能会遇到以下错误:

/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 特有的问题。我不确定。

【讨论】:

  • 是的,这对我有用。我只是扩展了gnustep-config --objc-flags 并使用了除D_NATIVE_OBJC_EXCEPTIONS 之外的所有参数。好收获!
【解决方案2】:

最好写一个 GNUmakefile。

http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/index.html

最好停止使用 gcc 并切换到 clang。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多