在c ++中修剪静态库 [英] Pruning a static library in c++

查看:108
本文介绍了在c ++中修剪静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过构建一个静态库,然后发运构建的库与一些头文件定义该类和使用它需要的接口,公开一个明确定义的类。我有工作,但我遇到的问题是图书馆是巨大的。它有来自整个项目的每个单个对象文件,我需要的是一个子集。如果我做一个简单的main.cpp文件并包含并使用那个单一的类,那么我得到一个只有我使用的库的20%的输出文件。有没有办法告诉链接器从一个给定的地方开始,并修剪一切,像在可执行的情况下?



编辑:我忘了提到我使用gcc在cygwin和linux(虽然我想要一个解决方案,工作与visual studio,我们通常使用它为开发,但主要部署在linux)

解决方案

创建共享库。它的行为就像一个可执行文件从链接的角度来看。它应该做你提到你在可执行文件上看到的废弃。


I am trying to expose a single well defined class by building a static library and then shipping the built library with a few header files that define that class and the interfaces needed to use it. I have that working but the problem I am running into is the library is gigantic. It has every single object file from the whole project and all I need is a subset. If I make a simple main.cpp file and include and use that single class then I get a output file that is only as big as the 20% of the library I am using. Is there a way to tell the linker to start from a given place and prune everything else like in the executable case?

EDIT: I forgot to mention that I am using gcc on cygwin and linux (though I would like a solution that worked with visual studio as well, we generally use that for development but deploy primarily on linux)

解决方案

Make a shared library. It behaves like an executable from the point of view of linking etc. It should do the discarding you mentioned you saw on the executable.

这篇关于在c ++中修剪静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆