在 Windows 上使用 GNUstep 编译 Objective-C 时无法找到标准库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/587421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:11:20  来源:igfitidea点击:

Unable to find standard libraries when compiling Objective-C using GNUstep on Windows

objective-cwindowsgnustep

提问by Jason Roberts

I just installed GNUstep on my Windows XP machine and I'm attempting to compile the following Objective-C Hello World program from the command line:

我刚刚在我的 Windows XP 机器上安装了 GNUstep,我正在尝试从命令行编译以下 Objective-C Hello World 程序:

#import <Foundation/Foundation.h>

int main(int argc, const char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSLog(@"Hello world\n");

    [pool drain];
    return 0;
}

When I try to compile the program from the command line like so

当我尝试像这样从命令行编译程序时

gcc hello.m -o hello

I end up getting the following error

我最终收到以下错误

hello.m:1:34: Foundation/Foundation.h: No such file or directory

Is there something I need to do order to inform the compiler of where the standard Objective-C libraries are located?

我需要做些什么来通知编译器标准 Objective-C 库的位置?

采纳答案by epatel

Have a look here. It seems like one needs a bunch of parameters to the compile command.

看看这里。似乎编译命令需要一堆参数。

回答by csk

try to run this command line in your command. it worked for me.

尝试在您的命令中运行此命令行。它对我有用。

gcc -I"c:/GNUstep/GNUstep/System/Library/Headers" -L "c:/GNUstep/GNUstep/System/Library/Libraries" -o hello helloWorld.m -lobjc -lgnustep-base -fconstant-string-class=NSConstantString

回答by csk

I just made a file called "GNUmakefile" and plonked this into it:

我刚刚制作了一个名为“GNUmakefile”的文件并将其插入其中:

include ${GNUSTEP_MAKEFILES}/common.make

TOOL_NAME = MyApp
MyApp_OBJC_FILES = code.m

include ${GNUSTEP_MAKEFILES}/tool.make

then I proceeded to just type 'make' at the prompt. The output is written out to obj\MyApp.exe

然后我继续在提示下输入“make”。输出写到 obj\MyApp.exe

That did it for me. screw stuffing about with gcc command line.

那是为我做的。用 gcc 命令行螺丝填充。

回答by Anil Kumar Yadav

GNUstep Installation Process For Windows

Windows 的 GNUstep 安装过程

  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.
  4. 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.
  5. Now you got the gnustep for windows then go to start>all program> GNUstep> shell
  6. Now open the notepad editor and write the following code in notepad:
  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 否则您的代码将无法运行。
  4. 首先安装 gnustep-system-0.19.2-setup.exe,然后安装 gnustep-core-0.19.2setup.exe。不要尝试以相反的顺序安装。
  5. 现在你得到了 windows 的 gnustep 然后去开始>所有程序> GNUstep> shell
  6. 现在打开记事本编辑器并在记事本中编写以下代码:

.

.

#import 'Foundation/Foundation.h'

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 envtheitroadment and make a folder by the name of your computer name in C:/GNUstep/home folder. So don't be panic.Okay

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

  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.
  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 中看到输出。

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

恭喜您成功编写了第一个 Objective C 程序。需要任何澄清写信给我:[email protected]

回答by Nosy Rat

OK I just realised the problem for me with this whole minw32, environment and gnustep core dev and why my make file wasn't working on a windows environment. Because I hadn't used the default options for the location when installing the packages.

好的,我刚刚意识到整个 minw32、环境和 gnustep 核心开发的问题,以及为什么我的 make 文件不能在 Windows 环境中工作。因为我在安装软件包时没有使用该位置的默认选项。

Makesure that all the 3 packages are installed on top of each other in the folder structure, as per default options. and I believe it starts in c:\GNUstep\

按照默认选项,确保所有 3 个包都安装在文件夹结构中的彼此之上。我相信它从 c:\GNUstep\ 开始

This solved all the environment problems like:

这解决了所有环境问题,例如:

Foundation/Foundation.h: no such file or directory

Foundation/Foundation.h:没有这样的文件或目录

objc/Object.h: No such file or directory

objc/Object.h: 没有那个文件或目录

Hope if helps anyone else in that cra-py long-winded situation.

希望如果能帮助其他人在那种糟糕的长篇大论的情况下。

回答by Richard

For my problem the deciding information was

对于我的问题,决定信息是

-fconstant-string-class=NSConstantString

from buggieboy above...

从上面的buggieboy...

回答by RobC

I know this is a late response, but the following website is great for getting you up and running with GNUstep, with the above and many other questions answered:

我知道这是一个迟到的回复,但以下网站非常适合让您开始使用 GNUstep,并回答了上述和许多其他问题:

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

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

It's helped me a ton.

它帮了我很多忙。

回答by Buggieboy

My GNUstep installation is in c:\GNUstep\GNUstep\System. If yours is different, you should change the import of Foundation.h accordingly.

我的 GNUstep 安装在 c:\GNUstep\GNUstep\System 中。如果您的不同,您应该相应地更改 Foundation.h 的导入。

I did this:

我这样做了:

  1. Create c:\myprogs\obj-c\hello\hello.m that looks like this:
  1. 创建如下所示的 c:\myprogs\obj-c\hello\hello.m:

//---------- Hello.m

//----------- 你好.m

#import <../../GNUstep/System/Library/Headers/Foundation/Foundation.h>

int main(int argc, const char* argv[])
{
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"Hello from Hello.m!");

    [pool release];
    return 0;
}

//----------

//-----------

  1. Start MinGW shell. (See above.)

  2. On shell command line, change to directory where program code is located. (Note that, since this is not Unix, the Windows drive letter must be included.):

    cd /c/myprogs/obj-c/hello

  3. Compile the program:

    gcc -o hello hello.m -I/c/GNUstep/GNUstep/System/Library/Headers \

    -L /c/GNUstep/GNUstep/System/Library/Libraries -lobjc -lgnustep-base \

    -fconstant-string-class=NSConstantString

  1. 启动 MinGW 外壳。(看上面。)

  2. 在 shell 命令行上,切换到程序代码所在的目录。(请注意,由于这不是 Unix,因此必须包含 Windows 驱动器号。):

    cd /c/myprogs/obj-c/hello

  3. 编译程序:

    gcc -o hello hello.m -I/c/GNUstep/GNUstep/System/Library/Headers \

    -L /c/GNUstep/GNUstep/System/Library/Libraries -lobjc -lgnustep-base \

    -fconstant-string-class=NSConstantString

(Note that "\" character allows us to extend command to multiple lines.)

(请注意,“\”字符允许我们将命令扩展到多行。)

I get the following informational messages when I compile:

我在编译时收到以下信息性消息:

Info: resolving ___objc_class_name_NSAutoreleasePool by linking to __imp____objc_class_name_NSAutoreleasePool (auto-import)
Info: resolving ___objc_class_name_NSConstantString by linking to __imp____objc_class_name_NSConstantString (auto-import)

Running resulting hello.exe gives me this:

运行结果 hello.exe 给了我这个:

2009-06-03 14:44:59.483 hello[1240] Hello from Hello.m!

回答by Buggieboy

You need to tell the compiler where the GNUstep headers and frameworks are located. The easiest way (at least on Unix systems, I'll be honest and say that I've not used GNUstep on Windows) is to use gnustep-make. You could have a GNUstep-make file as simple as

您需要告诉编译器 GNUstep 头文件和框架所在的位置。最简单的方法(至少在 Unix 系统上,老实说我没有在 Windows 上使用过 GNUstep)是使用 gnustep-make。你可以有一个简单的 GNUstep-make 文件

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = hello
hello_OBJC_FILES = hello.m

include $(GNUSTEP_MAKEFILES)/tool.make

回答by David Burton

I've been banging my head against this with GNUStep under Windows. The simplest tutorials get you to write a C program and compile it with GCC - if I wanted to do that then I wouldn't be bothering with GNUStep. The next level of tutorials do a hello world including the Foundation header and a simple GNUmakefile script, which then doesn't work under the Windows installation as you end up with following the GNUStep instructions. I know to open the shell that it's installed, but following the online tutorials for using a GNUmakefile file still didn't work. You got a whole series of errors from it trying to include the common makefile.

我一直在用 Windows 下的 GNUStep 反对这个。最简单的教程让您编写一个 C 程序并用 GCC 编译它——如果我想这样做,那么我就不会打扰 GNUStep。下一级别的教程介绍了一个 hello world,包括 Foundation 头文件和一个简单的 GNUmakefile 脚本,然后在 Windows 安装下无法运行,因为您最终会遵循 GNUStep 说明。我知道打开它已安装的外壳,但是按照使用 GNUmakefile 文件的在线教程仍然无效。您在尝试包含通用 makefile 时遇到了一系列错误。

Turns out the solution is pretty easy, you just aren't told to do it. GNUSTEP_MAKEFILES hasn't been set by the installer. If you add an environment variable called GNUSTEP_MAKEFILES with a value of /GNUstep/System/Library/Makefiles and then reopen the shell, then running make in your source folder with a GNUmakefile script can successfully include the common makefile and so on.

事实证明,解决方案非常简单,只是您没有被告知要这样做。安装程序尚未设置 GNUSTEP_MAKEFILES。如果您添加一个名为 GNUSTEP_MAKEFILES 且值为 /GNUstep/System/Library/Makefiles 的环境变量,然后重新打开 shell,则使用 GNUmakefile 脚本在源文件夹中运行 make 可以成功地包含通用 makefile 等。

This is then enough to get the makefile building a simple console application with the Foundation/Foundation.h header included, which bodes well, although I'll have to investigate further to see whether there's any more settings which haven't been set which affect, say, the GUI side of things.

这足以让 makefile 构建一个包含 Foundation/Foundation.h 标头的简单控制台应用程序,这预示着很好,尽管我必须进一步调查以查看是否还有其他尚未设置的设置会影响比如说,GUI 方面的事情。