本文介绍了CMake:如何构建共享和静态库,而不需要重新编译源两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要构建一个静态和共享版本的同一个库,如下所述
I want to build both a static and shared version of the same library as described Is it possible to get CMake to build both a static and shared version of the same library?
但是,源代码被编译两次,每个版本不一样。有没有办法避免这种情况?
However, the sources are compiled twice, one for each version which is not necessary. Is there any way to avoid this?
目前我有:
add_library(${LIB} SHARED ${${LIB}_srcs})
add_library(${LIB}_static STATIC ${${LIB}_srcs})
我需要改变什么才能只需要编译一次? FYI。
What do I need to change in order to only need to compile once? FYI. I have the same compiler flags and defines.
推荐答案
由于CMake 2.8.8可以使用对象库:。
Since CMake 2.8.8 you can use Object Library: CMake: reuse object files built for a lib into another lib target.
另请参阅
这篇关于CMake:如何构建共享和静态库,而不需要重新编译源两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!