Linking a shared library against a static library: must the static library be compiled differently than if an application were linking it?

后端 未结 3 2040
傲寒
傲寒 2020-12-13 09:42

At least on Linux and Solaris, static libraries are really just a bunch of compiled .o\'s tossed into one big file. When compiling a static library, usually the -fpic flag i

3条回答
  •  温柔的废话
    2020-12-13 10:19

    I do the following in the link stage for the shared object library version of a static library: g++ -shared -o libshared.so -Wl,--whole-archive -fPIC -lstatic -Wl,--no-whole-archive. Since --whole-archive links every object in a (list of) static libs (of the form libstatic.a) I believe preceding that (list) with -fPIC is all the OP need do.

提交回复
热议问题