Windows 下编译object-c

1. 搭建GNUStep
    http://www.gnustep.org/experience/Windows.html 

    下载四个文件 完全安装。

2. 配置GNUstep/etc/profile文件

在末尾加入如下配置(主要是配置msys环境):

GNUSTEP_MAKEFILES=/usr/GNUstep/System/Library/Makefiles/
LD_LIBRARY_PATH=/usr/local/lib/:/usr/GNUstep/Local/Library/Libraries/:/usr/GNUstep/System/Library/Libraries/
LIBRARY_PATH=/usr/local/lib/:/usr/GNUstep/Local/Library/Libraries/:/usr/GNUstep/System/Library/Libraries/
OBJC_INCLUDE_PATH=/usr/GNUstep/Local/Library/Headers/:/usr/GNUstep/System/Library/Headers/
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
PATH=$PATH:/usr/GNUstep/Local/Tools/:/usr/GNUstep/System/Tools/
export GNUSTEP_MAKEFILES LD_LIBRARY_PATH LIBRARY_PATH OBJC_INCLUDE_PATH PKG_CONFIG_PATH

3. 源文件和GNUmakefile

helloworld.m

#import <Foundation/Foundation.h>

int main(char argc, char* argv[]) {
NSLog(
@"hello world");
return0;
}

GNUmakefile

include $(GNUSTEP_MAKEFILES)/common.make 
TOOL_NAME = helloworld
helloworld_OBJC_FILES = helloworld.m 
include $(GNUSTEP_MAKEFILES)/tool.make

4. 编译

  通过gnustep shell进入home目录make一下就行了。(常用命令:ls pwd cd)

    看网上介绍的编译命令如:

#!/bin/sh

gcc
-o helloworld helloworld.m \
-fconstant-string-class=NSConstantString \
-I /GNUstep/System/Library/Headers/ \
-L /GNUstep/System/Library/Libraries/ \
-lobjc \
-lgnustep-base
基本上都是第三步中没有设置环境所以需要添加编译选项,使用makefile和第三步预设的编译环境基本可以解决编译问题了。

posted @ 2011-03-25 17:44  有只茄子  阅读(2120)  评论(0编辑  收藏  举报