繁体   English   中英

如何在osx上使用clang编译共享库

[英]How to compile shared lib with clang on osx

源文件

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上的相同代码可以轻松编译。

通过使用:

-Wl,-undefined -Wl,dynamic_lookup

要么

clang -shared -undefined dynamic_lookup -o libfoo.so foo.c

似乎保持了GCC的相同行为。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM