How to compile shared lib with clang on osx

主宰稳场 提交于 2019-12-03 12:38:53

问题


source file

rsetti::fastidio { /tmp }-> cat foo.c

    #include <stdio.h>
    void ACFunction() {
      printf("ACFunction()\n");
      AGoFunction();
    }

compilation of shared lib

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 }->

the same code on linux + gcc can be easily compiled.


回答1:


By using:

-Wl,-undefined -Wl,dynamic_lookup

or

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

seems to maintain the same behaviour of GCC.



来源:https://stackoverflow.com/questions/21907504/how-to-compile-shared-lib-with-clang-on-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!