如何使用 CMake 直接从目标文件构建库
给定一组目标文件,如何使用 CMake 构建静态库?
使用自动工具,我会将
libXXX.a: $(OBJFILES)
$(AR) cru $@ $(OBJFILES)
$(RANLIB) $@
OBJFILES 作为目标文件列表。
如何在 CMake 中做到这一点?
编辑:我无法重新编译原始 cxx 文件,我必须使用目标文件(*.o)来创建库。
Given a set of object files, how would you build a static library with CMake ?
With autotools I would do
libXXX.a: $(OBJFILES)
$(AR) cru $@ $(OBJFILES)
$(RANLIB) $@
OBJFILES being a list of object files.
How to do that in CMake ?
EDIT: I can't recompile the original cxx files, I have to use the object files (*.o) to create the library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加 自定义命令,例如:
如果需要,您可以使用 add_custom_target 和 add_dependency 将 libXXX.a 添加到特定目标,或者自定义依赖项。
Add a custom command, something like:
If necessary you can use add_custom_target and add_dependencies to add your libXXX.a to a specific target, or perhaps to customize the dependencies.
在
CMakeLists.txt
中使用add_library
:Use
add_library
inCMakeLists.txt
: