c/c++语言开发共享如何在osx上使用clang编译共享库

源文件

rsetti::fastidio { /tmp }-> cat foo.c #include  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的相同行为。

      以上就是c/c++开发分享如何在osx上使用clang编译共享库相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/572335.html

      (0)
      上一篇 2021年3月4日
      下一篇 2021年3月4日

      精彩推荐