如何在不使用CMake重新编译源代码的情况下构建共享库和静态库

如何在不使用CMake重新编译源代码的情况下构建共享库和静态库

问题描述:

我想构建与该库相同的静态版本和共享版本,如。但是,源代码被编译了两次,每个版本一个都没有必要。
避免这种情况的任何方法?

I want to build both a static and shared version of the same library as described here. However, the sources are compiled twice, one for each version which is not necessary. Any ways of avoiding this ?

取决于平台。至少在Linux上,您需要使用不同的编译器标志来生成与位置无关 (共享库)比普通(程序或静态库)代码。

Depends on the platform. On Linux at least, you need to use different compiler flags to produce position-independent (shared library) than ordinary (program or static library) code.