Objective-c 编译问题...帮忙吗?

发布于 2024-10-04 23:32:42 字数 377 浏览 5 评论 0原文

请原谅我,因为我也确信这个问题是在我预期之前就被问到的。 我遇到的问题是我正在尝试在电脑上学习 obj-c,因为我还没有 mac。我正在使用 Jedit 编写代码,并使用 GNUstep 进行编译和创建。 使用#include 进行编译时,我的问题出现了

然而,当我尝试根据我正在学习的书以及我在网上找到的其他所有内容(不太明白) ,我需要一个 make 文件或将我的编译器指向库或目录。我更喜欢我认为的 make 文件,因为测试和学习似乎更容易、更快。

主要问题是:我似乎找到了一个 GNUmake 文件,该文件随我的书的在线补充一起提供,但我不知道如何使用它或在哪里使用它。因此,如果有人能为我指出一个易于理解的过程或知道这样的过程并愿意传授这种智慧,我将不胜感激。

非常感谢您抽出时间

Please forgive me since this question i am also sure, has been asked before i expect.
The problem i am having is that i am trying to learn obj-c on a pc seeing as i do not have a mac yet. i am using Jedit to write my code and GNUstep to compile and create. however my problem is occurring when trying to compile using the #include

according to the book i am using to learn as well as everything else i have found online (and do not quite understand), i need either a make file or point my compiler at a library or directory. i would prefer the make file i suppose as it seems a lot easier and faster to test things and learn.

the main question then is this: i seem to have found a GNUmake file that came with the online additions to my book, but i do not know how to use it or where to go with it. so if some one can please point out for me a easy to understand process or knows of such process and would be willing to impart that wisdom, it would be much appreciated.

Thank you kindly for your time

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

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

发布评论

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

评论(1

荒路情人 2024-10-11 23:32:42

假设您已经正确安装了 GNUstep 并且您的环境已设置(所有内容都在文档中进行了解释),那么您实际上需要在项目的根目录中创建一个空白的 GNUmakefile 并在其中列出您的源代码。

下面是一个简单的“Hello World”命令行示例:

创建一个目录来包含源代码。 HelloWorld 将是一个好主意。

在其中创建文件 main.mGreeter.mGreeter.h

我们将创建 Greeter 类,该类只有一个方法 -sayHelloToRecipient:

Greeter.h 中:

#import <Foundation/Foundation.h>

@interface Greeter : NSObject {
}

-(void)sayHelloToRecipient:(NSString *)recipientName;

@end

Greeter.m 中:

#import "Greeter.h"

@implementation Greeter

-(void)sayHelloToRecipient:(NSString *)recipientName {
    NSLog(@"Hello %@!", recipientName);
}

@end

您的 main.m 文件仅包含 Greeter并使用参数@"World"调用它。

#import "Greeter.h"

int main(void) {
    Greeter *greeter = [[Greeter alloc] init];
    [greeter sayHelloToRecipient:@"World"];
    [greeter release];
    return 0;
}

现在您已准备好构建源代码,只需创建一个GNUmakefile。创建一个空文件,并以行 include $(GNUSTEP_MAKEFILES)/common.make 开头,以行 include $(GNUSTPEP_MAKEFILES)/tool.make 结尾。

第一行包括 GNUstep 提供的所有其他 makefile 和目标。最后一行包含生成命令行工具所需的 makefile。如果您要构建 GUI 应用程序,则需要包含 application.make。对于框架,您将包括 framework.make 等。

include $(GNUSTEP_MAKEFILES)/common.make

# Your project-specific directives will go here

include $(GNUSTEP_MAKEFILES)/tool.make

您在这些行之间放置的内容是随项目而变化的内容。

完整的 GNUmakefile 如下所示:

include $(GNUSTEP_MAKEFILES)/common.make

HELLO_ROOT_DIR = $(abspath .)

GNUSTEP_BUILD_DIR = $(HELLO_ROOT_DIR)/build

TOOL_NAME = HelloWorld

HelloWorld_OBJC_FILES = \
    Greeter.m \
    main.m

include $(GNUSTEP_MAKEFILES)/tool.make

HELLO_ROOT_DIR 完全是可选的,它只是一个变量,它使我不必随着项目的增长而重新输入根目录的路径(并且makefile 的复杂性也如此)。

TOOL_NAME 是命令行工具所必需的,它指定输出文件名,并确定 *_OBJC_FILES 行需要使用的内容(即在本例中我需要使用HelloWorld_OBJC_FILES 因为 TOOL_NAME 是“HelloWorld”,

只要您与 makefile 位于同一目录中,您应该只需键入“make”即可。它将创建一个“build”目录,在该目录中您将找到可执行文件,该目录在调用时仅输出:

-$  ./build/obj/HelloWorld 
2010-11-28 03:36:28.459 HelloWorld[12949] Hello World!

但是,如果您的环境配置不正确,则这些都不会起作用。 Windows,但我假设同样的原则适用。在 Linux/UNIX 上运行 shell 脚本(在 Windows 上运行批处理文件?)以配置环境,

-$  . /usr/share/GNUstep/Makefiles/GNUstep.sh

您可以通过打印环境变量 GNUSTEP_MAKEFILES 来检查它是否正确配置 。 到控制台:(

-$  echo $GNUSTEP_MAKEFILES

不确定在 Windows 上如何执行此操作)

如果它没有输出任何内容,则说明您的环境配置不正确和/或 GNUstep 未正确安装。如果它输出一个路径,你应该可以安全地运行“make”。

Assuming you have installed GNUstep correctly and your environment is set up (all explained in the documentation) then you actually need to create a blank GNUmakefile in the root directory of your project and list your sources in that.

Here's a simple "Hello World" command line example:

Create a directory to contain your source code. HelloWorld would be a good idea.

In that, create files main.m, Greeter.m and Greeter.h.

We'll create the Greeter class which will just have one method -sayHelloToRecipient:.

In the Greeter.h:

#import <Foundation/Foundation.h>

@interface Greeter : NSObject {
}

-(void)sayHelloToRecipient:(NSString *)recipientName;

@end

And in the Greeter.m:

#import "Greeter.h"

@implementation Greeter

-(void)sayHelloToRecipient:(NSString *)recipientName {
    NSLog(@"Hello %@!", recipientName);
}

@end

Your main.m file simply includes the Greeter and invokes it with the argument @"World".

#import "Greeter.h"

int main(void) {
    Greeter *greeter = [[Greeter alloc] init];
    [greeter sayHelloToRecipient:@"World"];
    [greeter release];
    return 0;
}

Now you've got your sources ready to build, you just need to create a GNUmakefile. Make an empty file, and start it with the line: include $(GNUSTEP_MAKEFILES)/common.make, ending with the line include $(GNUSTPEP_MAKEFILES)/tool.make.

The first line includes all the other makefiles and targets GNUstep provides. The last line includes the makefiles needed to produce a command line tool. If you were build a GUI app you'd include application.make. For frameworks you'd include framework.make etc.

include $(GNUSTEP_MAKEFILES)/common.make

# Your project-specific directives will go here

include $(GNUSTEP_MAKEFILES)/tool.make

The stuff you put between these lines is the stuff that changes from project to project.

The complete GNUmakefile looks like this:

include $(GNUSTEP_MAKEFILES)/common.make

HELLO_ROOT_DIR = $(abspath .)

GNUSTEP_BUILD_DIR = $(HELLO_ROOT_DIR)/build

TOOL_NAME = HelloWorld

HelloWorld_OBJC_FILES = \
    Greeter.m \
    main.m

include $(GNUSTEP_MAKEFILES)/tool.make

HELLO_ROOT_DIR is entirely optional and is just a variable that saves me from having to re-type the path to the root as the project grows (and so does the complexity of the makefile).

TOOL_NAME is required for a command line tool and specifies both the output filename, and determines what you need to use for the *_OBJC_FILES line (i.e. in this case I need to use HelloWorld_OBJC_FILES because TOOL_NAME is "HelloWorld".

With this in place, provided you're in the same directory as the makefile, you should be able to just type `make' to build the tool. It will create a "build" directory and inside that you'll find the executable. This one when invoked just outputs:

-$  ./build/obj/HelloWorld 
2010-11-28 03:36:28.459 HelloWorld[12949] Hello World!

None of this will work however if your environment is not configured correctly. I've never done this on Windows, but I assume the same principles apply. That's running a shell script on Linux/UNIX (running batch file on Windows?) in order to configure the environment.

-$  . /usr/share/GNUstep/Makefiles/GNUstep.sh

You can check if it's correctly configured by printing the environment variable GNUSTEP_MAKEFILES to the console:

-$  echo $GNUSTEP_MAKEFILES

(Not sure how you do this on Windows)

If it outputs nothing, your environment is not correctly configured and/or GNUstep is not correctly installed. If it outputs a path, you should be safe to run `make'.

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