Foundation.h 错误
-
21-09-2019 - |
题
我在 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:~$
我需要做什么?
解决方案
Windows 下的 GNUstep 安装过程
- 访问网址: http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/
- 下载exe文件gnustep-system-0.19.2-setup.exe
- 然后下载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,否则您的代码将无法运行。
- 首先安装 gnustep-system-0.19.2-setup.exe,然后安装 gnustep-core-0.19.2setup.exe。不要尝试以相反的顺序安装。
- 现在你已经获得了 Windows 版的 gnustep,然后转到开始>所有程序> GNUstep> shell
- 现在打开记事本编辑器并在记事本中编写以下代码
#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; }
将其另存为hello.m。文件夹。所以不要惊慌。好的
- 转到 shell 并键入以下命令 gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -constant-string-class=NSConstantString
- 此命令将在您的foldername 文件夹中创建一个hello.exe 文件。
- 再次在 shell 中输入命令 ./hello.exe
最后你将能够在 shell 中看到输出。
恭喜您成功编写了第一个 Objective C 程序。需要任何澄清请写信给我:aayadav00009@gmail.com
其他提示
你是如何编制的?对于我来说,我创建了一个GNUMakefile
的makefile我的应用程序(见 rel="noreferrer">这里) ,然后我运行source /usr/share/GNUstep/Makefiles/GNUstep.sh
然后make
。
我搜索的资料库,然后我安装了基础lib下,现在所有的工作。
感谢。
不隶属于 StackOverflow