目前我在使用Xcode 4.0.2的Mac OS X 10.6.7上遇到了弱链接问题.
robin@chameleon:/tmp/o$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Run Code Online (Sandbox Code Playgroud)
正如文档http://developer.apple.com/library/mac/#technotes/tn2064/_index.html所说,我们可以使用gcc 属性((weak_import))作为弱链接符号.但是,以下示例代码始终抛出编译错误.如下:
weak.c:
#include <stdlib.h>
#include <stdio.h>
extern int SayHello() __attribute__((weak));
int main()
{
int result;
if (SayHello!=NULL)
{
printf("SayHello is present!\n");
result=SayHello();
}
else
printf("SayHello is not present!\n");
}
Run Code Online (Sandbox Code Playgroud)
错误消息如下:
robin@chameleon:/tmp/o$ gcc weak.c
Undefined symbols for architecture x86_64:
"_f", referenced from:
_main in cceOf2wN.o
(maybe you meant: __dyld_func_lookup)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned …Run Code Online (Sandbox Code Playgroud)