【问题标题】:Error With Foundation.hFoundation.h 出错
【发布时间】:2009-10-18 00:02:13
【问题描述】:

我在 Linux(Ubuntu) 中学习 Objective-C,但是当我尝试编译需要 Foundation 头文件的应用程序时,我收到一条错误消息,提示找不到文件,但我已经安装了 GNUstep 开发包(gnustep-开发)。这是我的代码:

// Fraction.h
#import <Foundation/NSObject.h>

@interface Fraction: NSObject {
    int numerator;
    int denominator;
}

- (void) print;
- (void) setNumerator: (int) n;
- (void) setDenominator: (int) d;
- (void) numerator;
- (void) denominator;
@end

这是控制台日志:

ubuntu@eeepc:~$ gcc main.m -o frac -lobjc
In file included from main.m:3:
Fraction.h:2:26: error: objc/NSObject.h: No such file or directory
In file included from main.m:3:
Fraction.h:4: error: cannot find interface declaration for ‘NSObject’, superclass of ‘Fraction’
ubuntu@eeepc:~$

我需要做什么?

【问题讨论】:

    标签: objective-c foundation gnustep


    【解决方案1】:

    你是如何编译它的?对于我来说,我为我的应用程序创建了一个GNUMakefile makefile(参见here),然后运行source /usr/share/GNUstep/Makefiles/GNUstep.sh,然后运行make

    【讨论】:

    • GNUmakefile : include $(GNUSTEP_MAKEFILES)/common.make TOOL_NAME = LogTest LogTest_OBJC_FILES = source.m include $(GNUSTEP_MAKEFILES)/tool.make
    【解决方案2】:

    GNUstep Windows 安装过程

    1. 访问网址:http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/
    2. 下载exe文件gnustep-system-0.19.2-setup.exe
    3. 然后下载 gnustep-core-0.19.2-setup.exe

    如果您要下载任何版本的 gnustep-system,请记住一件事,您必须为 gnustep-core 下载相同版本。 例如,如果您下载了 gnustep-setup-0.22.1-setup.exe,那么您必须下载 gustep-core-0.22.1-setup.exe,否则您的代码将无法运行。

    1. 首先安装 gnustep-system-0.19.2-setup.exe,然后安装 gnustep-core-0.19.2setup.exe。不要尝试以相反的顺序安装。
    2. 现在您已经获得了适用于 windows 的 gnustep,然后转到 start>all program> GNUstep> shell
    3. 现在打开记事本编辑器,在记事本中写入以下代码
    #import
    int main (int argc, const char * argv[])
    {
      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]
    在里面];
      NSLog (@"Anil Kumar Yadav 已经运行了第一个目标 C
    程序!”);
      [池排水];
      返回0;
    }

    在你的 C:/GNUstep/home/foldername 中将它保存为 hello.m 请记住,foldername 是您第一次启动 shell 时的名称,它会创建环境并在 C:/GNUstep/home 文件夹中使用您的计算机名称创建一个文件夹。所以不要惊慌。好吧

    1. 转到您的 shell 并键入以下命令 gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -constant-string- class=NSConstantString
    2. 此命令将在您的文件夹名称文件夹中创建一个 hello.exe 文件。
    3. 再次在 shell 中键入命令 ./hello.exe

    终于可以在shell中看到输出了。

    恭喜你成功编写了你的​​第一个 Objective C 程序。 需要任何澄清写信给我:ayadav00009@gmail.com

    【讨论】:

    • 你实际上必须#import &lt;&gt;一个头文件。只使用#import 而不跟随它会导致编译错误。例如使用#import &lt;Foundation/Foundation.h&gt;
    • 用户询问有关 linux (ubuntu) 的说明。这些是适用于 Windows 的说明。
    【解决方案3】:

    我搜索了存储库,然后我安装了基础库,现在一切正常。

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多