Ger*_*emy 8 linux ubuntu objective-c gnustep
似乎有很多关于如何做到这一点的教程,每个都略有不同.我希望有人能够认出我收到的错误信息,并指出我正确的方向.
我的代码,hm是:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"hello world");
[pool drain];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在编译之前,我进入控制台:
. /usr/share/GNUstep/Makefiles/GNUstep.sh
Run Code Online (Sandbox Code Playgroud)
我尝试编译:
gcc `gnustep-config --objc-flags` -lgnustep-base h.m -o hello
Run Code Online (Sandbox Code Playgroud)
得到:
/tmp/ccgLOnpY.o: In function `main': /home/ge/objective-c/h.m:4: undefined reference to `objc_get_class' /home/ge/objective-c/h.m:4: undefined reference to `objc_msg_lookup' /home/ge/objective-c/h.m:4: undefined reference to `objc_msg_lookup' /home/ge/objective-c/h.m:5: undefined reference to `NSLog' /home/ge/objective-c/h.m:6: undefined reference to `objc_msg_lookup' /tmp/ccgLOnpY.o: In function `__objc_gnu_init': /home/ge/objective-c/h.m:8: undefined reference to `__objc_exec_class' /tmp/ccgLOnpY.o:(.data.rel+0x0): undefined reference to `__objc_class_name_NSConstantString' /tmp/ccgLOnpY.o:(.data.rel+0x8): undefined reference to `__objc_class_name_NSAutoreleasePool' collect2: ld returned 1 exit status
有人能指出我正确的方向吗?
TIA
ano*_*ard 30
链接错误的原因很可能是由于链接器仅在链接库之前在编译中看到符号后链接库的行为.由于尚未遇到库中的符号而未链接库,因此h.m显示-lgnustep-base.即使使用-Wl,--no-as-needed链接器选项 未遇到符号,您也可以指示链接器链接库
gcc `gnustep-config --objc-flags` -Wl,--no-as-needed -lgnustep-base h.m -o hello
Run Code Online (Sandbox Code Playgroud)
或者更好,只需将源移动到编译命令的开头即可
gcc h.m `gnustep-config --objc-flags` -lgnustep-base -o hello
Run Code Online (Sandbox Code Playgroud)
观察到的链接器行为是为了阻止查找和链接库的符号,这些符号可能是不需要的,但无论如何都在编译中链接,因此第二种选择是建议的方式,而不是添加-Wl, --no-as-needed链接器选项.
希望这可以帮助!
and*_*n22 10
你需要链接到libobjc.修复非常简单; 只需编译:
gcc h.m `gnustep-config --objc-flags` -lobjc -lgnustep-base -o hello
Run Code Online (Sandbox Code Playgroud)
小智 5
您还需要指定链接标志:
gcc h.m `gnustep-config --objc-flags` `gnustep-config --objc-libs` \
-lobjc -lgnustep-base -o hello
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5374 次 |
| 最近记录: |