【发布时间】:2016-05-18 05:16:38
【问题描述】:
考虑这种情况(一切都处于发布模式):
a.lib includes f1() and f2().
a.lib is built using /LTCG on VS2015.
f1() is local without any external function calls.
f2() calls fc() from b.lib
b.lib includes fc() and 100s of other functions.
b.lib is built by a 3rd party, probably not VS.
main.exe is built only with main.cpp, using /LTCG on VS2015.
main.exe links to a.lib and b.lib
main.cpp only calls f1()
现在,当我构建 main.exe 时,我希望它只包含 f1() 的实现。可执行文件大小约为 10MB。
但是,如果我在 a.lib 中注释掉 f2() 的实现并重新构建 a.lib,则 main.exe 变为 200KB。它在两种情况下的工作方式完全相同。
我担心的是可执行文件的大小以及不必要地暴露有关 b.lib(这不是我自己的库)的任何内容。
问题:为什么链接器不够聪明,不能不包含 f2()->fc() 定义?虽然它足够聪明,不会包含 b.lib 的其余部分(超过 100MB)?
【问题讨论】:
-
您能否尝试使用 C/C++ /Gy 选项构建 a.lib 并使用链接器 /OPT 选项链接您的可执行文件?
-
/Gy 已为 a.lib 定义,可执行文件 /OPT:ICF 和 /OPT:REF 已启用。你有另一个 /OPT 的想法吗?
标签: c++ c visual-studio