Foundation.h 错误

发布于 2024-08-07 21:37:16 字数 772 浏览 13 评论 0原文

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

// 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:~$

我需要做什么?

I learning Objective-C in Linux(Ubuntu), but when i tryed to compile my application that needs the Foundation headers i got an error saying that the file cannot be found, but i have installed the GNUstep development package(gnustep-devel). Here is my code:

// 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

And here is the console log:

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:~$

What i need to do?

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

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

发布评论

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

评论(3

断舍离 2024-08-14 21:37:16

你是怎么编译的?对我来说,我为我的应用程序创建了一个 GNUMakefile makefile(请参阅 此处),然后运行source /usr/share/GNUstep/Makefiles/GNUstep.sh,然后运行make

how are you compiling it? For me, I create a GNUMakefile makefile for my application (see here), and then I run source /usr/share/GNUstep/Makefiles/GNUstep.sh and then make.

北笙凉宸 2024-08-14 21:37:16

适用于 Windows 的 GNUstep 安装过程

  1. 请访问 URL: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,然后转到“开始”>“所有程序”> GNUstep> shell
  3. 现在打开记事本编辑器并在记事本中编写以下代码,
#import  
int main (int argc, const char * argv[])
{
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]  
init];
  NSLog (@"Anil Kumar Yadav has Run the First Objective C  
program!");
  [pool drain];
  return 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. 此命令将在您的foldername 文件夹中创建一个hello.exe 文件。
  3. 再次在 shell 中输入命令 ./hello.exe

最后您将能够在 shell 中看到输出。

恭喜您成功编写了第一个 Objective C 程序。
需要任何说明请写信给我:[电子邮件受保护]

GNUstep Installation Process For Windows

  1. Visit The URL: http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/
  2. Download the exe file gnustep-system-0.19.2-setup.exe
  3. Then Download gnustep-core-0.19.2-setup.exe

Remember one thing if you are downloading gnustep-system of any version you must have to download the same version for gnustep-core.
For example if you have downloaded gnustep-setup-0.22.1-setup.exe then you must have to download gustep-core-0.22.1-setup.exe otherwise your code will not run.

  1. Install first the gnustep-system-0.19.2-setup.exe then install gnustep-core-0.19.2setup.exe. Don’t try to install in vice versa order.
  2. Now you got the gnustep for windows then go to start>all program> GNUstep> shell
  3. Now open the notepad editor and write the following code in notepad
#import  
int main (int argc, const char * argv[])
{
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]  
init];
  NSLog (@"Anil Kumar Yadav has Run the First Objective C  
program!");
  [pool drain];
  return 0;
}

save it as hello.m in your C:/GNUstep/home/foldername
Remember foldername is the name when you first time start the shell it create the envoirment and make a folder by the name of your computer name in C:/GNUstep/home folder. So don’t be panic.Okay

  1. Go to your shell and type the following command gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -constant-string-class=NSConstantString
  2. This command will create a hello.exe file in your foldername folder.
  3. Again in shell type the command ./hello.exe

Finally you will be able to see the output in the shell.

Conguratulation you wrote your first Objective C program successfully.
Need any clarification write me to : [email protected]

尝蛊 2024-08-14 21:37:16

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

谢谢。

I've searched at the repository and then i installed the foundation lib, now all is working.

Thanks.

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