我是 LLVM 新手。我昨天通过 GnuStep 在 Windows 上构建了 LLVM 和 Clang。
LLVM+CLang:3.2
GCC:4.6.1(GnuStep)
OS:Win7 64
我可以将 Objective-c 源文件编译为 bitcode 和 exe。该 exe 有效,但是当我尝试执行 bitcode 时,出现此错误:
LLVM ERROR: Could not resolve external global address:
_OBJC_CLASS_NSConstantString
问题:
How can I load dll or lib files in llvm?
How can I link lib files(ex: libobjc.dll.a) to bitcode? Is that possible?
你好.m
#import <Foundation/Foundation.h>
int main(int argc, char**argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello Objective-C\n");
[pool release];
return 0;
}
生成文件
CC=gcc
CCFLAGS=-fconstant-string-class=NSConstantString -ID:/GNUstep/GNUstep/System/Library/Headers
LDFLAGS=-LD:/GNUstep/GNUstep/System/Library/Libraries/ -lobjc -lgnustep-base
CLANG=clang
CLANG_FLAG=-c -fobjc-runtime=gcc -emit-llvm
LLC=llc
LLI=lli
LLI_FLAG=-load=D:\GNUstep\GNUstep\System\Tools\objc-4.dll -load=D:\GNUstep\GNUstep\System\Tools\gnustep-base-1_24.dll
#LLI_FLAG=-load=D:\GNUstep\GNUstep\System\Library\Libraries\libgnustep-base.dll.a -load=D:\GNUstep\GNUstep\System\Library\Libraries\libobjc.dll.a
all:hello.obj hello1.exe
hello.exe: hello.o
$(CC) -o hello.exe hello.o $(LDFLAGS)
hello.obj: hello.bc
$(LLC) -filetype=obj hello.bc
hello.bc:hello.m
$(CLANG) -o hello.bc hello.m $(CLANG_FLAG) $(CCFLAGS)
hello1.exe: hello.m
$(CLANG) hello.m -o hello1.exe $(CCFLAGS) $(LDFLAGS)
run:
#Err
$(LLI) $(LLI_FLAG) -force-interpreter=false hello.bc
#OK
hello.exe
#OK
hello1.exe
clean:
rm *.o
rm *.exe
rm *.bc