使用clang从cpp文件创建动态库和静态库

3
我有一个问题:
我有一个名为libAlgatorc.a的静态库和三个cpp文件,分别是SortingAbsAlgorithm.cppSortingTestCase.cppSortingTestSetIterator.cpp
现在,我想创建一个动态库,其中包含来自cpp文件和静态库的符号。我可以在Linux(Ubuntu 12.04 x64,g++版本4.8.1)中这样做:
g++ -fPIC SortingAbsAlgorithm.cpp SortingTestCase.cpp SortingTestSetIterator.cpp -shared -o libProject.so -Wl,--whole-archive -lAlgatorc -Wl,--no-whole-archive

但是在OS X上我无法做到这一点。clang没有-Wl,--whole-archive选项。

我的clang版本如下:

$ clang --version
Apple LLVM version 7.0.0 (clang-700.0.53.3)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

有什么建议吗?

1个回答

3

来自苹果公司的动态库编程主题,可能是类似以下内容:

clang -dynamiclib \
    SortingAbsAlgorithm.cpp SortingTestCase.cpp SortingTestSetIterator.cpp \
    -stdlib=libc++ -current_version 1.0 -compatibility_version 1.0 \
    -fvisibility=hidden -L. -lAlgatorc -o libProject.dylib

鉴于我已经指定了 -stdlib=libc++,您可能还需要添加 -mmacosx-version-min=10.7

所以实际上只有 -dynamiclib 是重要的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接