源文件
rsetti::fastidio { /tmp }-> cat foo.c
#include <stdio.h>
void ACFunction() {
printf("ACFunction()\n");
AGoFunction();
}
共享库的编译
rsetti::fastidio { /tmp }-> clang -shared -o libfoo.so foo.c
foo.c:4:3: warning: implicit declaration of function 'AGoFunction' is invalid in C99 [-Wimplicit-function-declaration]
AGoFunction();
^
1 warning generated.
Undefined symbols for architecture x86_64:
"_AGoFunction", referenced from:
_ACFunction in foo-lFDQ4g.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
rsetti::fastidio { /tmp }->
linux + gcc上的相同代码可以轻松编译。
答案 0 :(得分:20)
使用:
-Wl,-undefined -Wl,dynamic_lookup
或
clang -shared -undefined dynamic_lookup -o libfoo.so foo.c
似乎保持了GCC的相同行为。