当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
5 Star 38 Fork 7

初雨团队 / VC-LTL
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
ReadMe.osc.md
EPL-2.0

VC-LTL——编译精巧的程序原来如此简单

license downloads contributors release nuget

Logo
我愿化成一座做石桥,经受五百年的风吹,五百年的日晒,五百年的雨打,只求她从桥上走过!

1. 关于VC-LTL

VC-LTL是一个基于微软VC修改的开源运行时,有效减少应用程序体积并摆脱微软运行时DLL,比如msvcr120.dll、api-ms-win-crt-time-l1-1-0.dll等依赖。

VC-LTL最初是Dism++专用运行时。2017年3月6号从Dism++源代码中分离,并正式对外开源,为社区贡献自己的微薄之力。

在大型项目中往往有众多模块,如果都采用静态编译那么造成的空间浪费先不说,最后也会因为Fls上限导致程序无法正常运行。

而VC-LTL能让你的项目如同系统文件一样共享系统内置msvcrt.dll,有效的解决Fls上限以及运行时部署问题,同时大大缩减程序体积,可以说一箭三雕!

所有人都可以无条件、免费使用,包括用于商业环境。当然如果大家在自己的程序说明文件中声明使用了VC-LTL那就更好了。

1.1. 原理

使用VC-LTL后可以将程序动态链接到系统自带的msvcrt.dll中,来减少程序体积。目前使用CRT以及STL的工程一般都可以使用。但是MFC工程不能使用,因为MFC类库太复杂了,尚未适配。

使用VC-LTL,C++程序体积大约缩减30%,而纯C程序则大约缩减50%。

1.2. 亮点

  • 晚起的鸟儿也有虫虫吃,优雅的引用方式,仅添加一个属性表就能享受极致的体积体验。
  • 无缝使用最新C/C++库以及最新编译器,尽情的使用最新规范。神马异常流防护(guard:cf)、静态对象线程安全初始化(threadSafeInit)……统统放马过来吧!!
  • 拥有比微软原版更好的兼容性,即使想兼容Windows XP RTM也可以安心的对新编译器说“Yes”。
  • 完全的开放代码,广泛的接受用户意见,希望大家能踊跃的 pull requests,为VC-LTL添砖加瓦。

让我们一起跟VS 2008说拜拜!

2. VC-LTL兼容性

此表展示了VC-LTL,C/C++库函数覆盖率,通过覆盖情况,可以大致了解VC-LTL的完善程度。

模块 XP模式 Vista模式 UCRT模式 相关文件
CRT 94.716% 96.347% 100% vcruntime.lib、libvcruntime.lib、msvcrt.lib、msvcmrt.lib、msvcrt_Platform.lib、libucrt.lib、ucrt.lib、libucrt_shared.lib、vc.lib
STL 100% 100% 100% libcpmt.lib、msvcprt.lib
ConcRT 100% 100% 100% libconcrt.lib、concrt.lib
WinRT X 100% X vccorlib.lib(仅支持Windows 8.1以及更高版本)
ATL 100% 100% 100% -
MFC X X 100% -
AMP X X X -
OpenMP 100% 100% 100% Visual Studio自身提供,需要带上vcomp140.dll

2.1. 支持的IDE

  • Visual Studio 2015(包含Clang with Microsoft CodeGen、Clang 3.7 with Microsoft CodeGen、Clang-LLVM)
  • Visual Studio 2017(包含Clang with Microsoft CodeGen、Clang-LLVM)
  • Visual Studio 2019(包含Clang-LLVM)

2.2. 支持的编译工具

编译工具 支持文件
Visual Studio VC-LTL helper for Visual Studio.props
CMake VC-LTL helper for cmake.cmake
NMake、CL VC-LTL helper for nmake.cmd
QMake VC-LTL helper for qmake.pri

2.3. 支持的操作系统

操作系统 x86 x64 arm arm64
Windows XP、Windows Server 2003 - -
Windows Vista、Windows Server 2008 - -
Windows 7、Windows Server 2008 R2 - -
Windows 8、Windows Server 2012、Windows RT -
Windows 8.1、Windows Server 2012 R2、Windows RT 8.1 -
Windows 10、Windows Server 2016、Windows Server 2019

采用VC-LTL编译后的程序能兼容Windows XP RTM以上所有操作系统,无需安装任何SP补丁包。

3. 使用方法

下面我们将进入主题,我们给大家准备了丰富的VC-LTL示例供大家参考,也欢迎加入我们的QQ群(633710173)。

3.1. 在Visual Studio中使用VC-LTL

3.1.1. 引用VC-LTL

3.1.1.1. 通过NuGet引用(推荐)

在 项目右键,选择“管理 NuGet 程序包”,然后搜索 VC-LTL 并选择适合您的版本,最后点击安装即可。

InstallByNuGet

3.1.1.2. 通过注册表引用

假如,你将VC-LTL Binary下载并解压至D:\Src\VC-LTL(具体位置无任何要求),双击D:\Src\VC-LTL\Install.cmd即可。

脚本会在HKCU\Code\VC-LTL创建注册表。

将属性表VC-LTL helper for Visual Studio.props复制到你的工程目录,你可以打开属性管理器(视图 - 属性管理器),然后Release配置上右键添加现有属性表,然后选择VC-LTL helper for Visual Studio.props即可。

AddShared

3.1.2. 配置工程属性

  • C/C++ - 代码生成 -【运行库】调整为【多线程 (/MT)】

ConfigurationProject

如需支持XP,请右键项目 - 属性 - 初雨团队 VC-LTL - 启用 Windows XP 兼容 -『是』 即可。

3.2. 在CMake中使用VC-LTL

假如,你将VC-LTL Binary下载并解压至D:\Src\VC-LTL(具体位置无任何要求),双击D:\Src\VC-LTL\Install.cmd即可。

脚本会在HKCU\Code\VC-LTL创建注册表。

3.2.1. 添加VC-LTL配置文件

将模块文件VC-LTL helper for cmake.cmake复制到你的工程目录(顶层CMakeLists.txt同级目录)。然后在CMakeLists.txt中添加一行 include("VC-LTL helper for cmake.cmake") 即可。

示例:

cmake_minimum_required(VERSION 3.5.2)
project(ltltest)

include("VC-LTL helper for cmake.cmake")

add_subdirectory(src)

3.2.2. 调整配置工程

务必确保使用/MT编译代码。如需支持XP,请修改VC-LTL helper for cmake.cmake启用 set(SupportWinXP "true") 即可。

3.3. 在NMake/纯CL中使用VC-LTL

假如,你将VC-LTL Binary下载并解压至D:\Src\VC-LTL(具体位置无任何要求),双击D:\Src\VC-LTL\Install.cmd即可。

脚本会在HKCU\Code\VC-LTL创建注册表。

3.3.1. 运行VC-LTL辅助脚本

将辅助脚本VC-LTL helper for nmake.cmd复制到你的工程目录。启动vcvars32.bat/vcvars64.bat执行此脚本即可,脚本将自动修改include以及lib环境变量。

示例:

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"
call "D:\VC-LTL\VC-LTL helper for nmake.cmd"

nmake /f Test.mak

3.3.2. 配置工程属性

务必确保使用/MT编译代码。如需支持XP,请修改VC-LTL helper for nmake.cmd启用 set SupportWinXP=true

3.4. 重新编译(仅Release)

现在是不是体积就小了很多。如果你编译不通过,可以先参考 4. 常见问题。如果还是不通过可以反馈,共同改进VC-LTL。

如果正确引用VC-LTL,那么 会在生成时输出:note: 进入ltl普通模式,已准备引用到VC-LTL。定义 _DISABLE_DEPRECATE_LTL_MESSAGE 可关闭信息提示。

使用VC-LTL编译时必须采用/MT编译,并且所有依赖的静态库也必须使用VC-LTL重新编译。

AppBuildByVC-LTL

4. 常见问题

4.1. 未共享到msvcrt.dll

问题原因

未正确引用VC-LTL。建议看看生成日志,是否包含:note: 进入ltl普通模式,已准备引用到VC-LTL。定义 _DISABLE_DEPRECATE_LTL_MESSAGE 可关闭信息提示。

解决方案

1:请务必确保 VC-LTL helper for Visual Studio.props 已经添加到工程。

2:确保以下设置正确:

  • VC++ 目录 - 包含目录 - 【√ 从父项或项目默认设置继承(I)】
  • VC++ 目录 - 库目录 - 【√ 从父项或项目默认设置继承(I)】

4.2. 无法解析外部符号 delete 等

问题原因

没有正确引入vc.lib、msvcrt_Platform.lib。

解决方案

  • VC++ 目录 - 包含目录 - 【√ 从父项或项目默认设置继承(I)】
  • VC++ 目录 - 库目录 - 【√ 从父项或项目默认设置继承(I)】

4.3. 检测到RuntimeLibrary的不匹配项

问题原因

引入了没有使用VC-LTL编译的静态lib文件。

解决方案

使用VC-LTL重新编译对应的静态lib(具体lib名称错误日志会给出)。

5. 已知问题

  • 由于WinXP本身Bug,printf相关函数输入缓冲区最大字符数为0x3FFFFFFF(包含)。当你需要兼容XP时,请务必确认缓冲区输入长度小于0x3FFFFFFF,或者直接使用 _CRT_STDIO_SIZE_MAX 宏。(4.0.2.5 Advanced模式已经修正此问题)。
  • 由于WinXP本身Bug,printf相关函数无法正常支持%ll。当你需要兼容XP时,请优先考虑使用%I64代替。(4.0.2.5 Advanced模式已经修正此问题)。
  • 由于msvcrt本身限制,setlocale/_create_locale相关函数不支持UCRT的locale name,使用时必须按VC 2008规范使用,比如 setlocale(0, "chs"); 这样调用,而不是传入 setlocale(0, "zh-CN");

附:已知使用VC-LTL的官方项目

项目 备注
NSudo 一个强大的系统管理工具。VC-LTL的帮助下减少30%的程序体积,包括NSudo for arm64。
Menu98 经典样式可自定义的开始按钮右键菜单。使用VC-LTL移除运行时依赖。
壁虎浏览器 一款专业解决DNS劫持的浏览器。使用VC-LTL有效减少程序体积,减少安装包大小。
librech551 开源跨平台的CH55x ISP软件。使用VC-LTL移除运行时依赖。
Dism++ Dism GUI版。初雨团队自身项目,使用VC-LTL有效减少程序体积,减少安装包大小。
360安全卫士 奇虎360推出的上网安全软件。360EvtMgr.exe、360leakfixer.exe、360Util.dll、leakrepair.dll等文件使用VC-LTL编译,在VC-LTL的支持下:升级新编译器,减少文件尺寸,完美兼容WinXP,一箭三雕。

附:第三方依赖项许可

更新日志

更新日志

Eclipse Public License - v 2.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 1. DEFINITIONS "Contribution" means: a) in the case of the initial Contributor, the initial content Distributed under this Agreement, and b) in the case of each subsequent Contributor: i) changes to the Program, and ii) additions to the Program; where such changes and/or additions to the Program originate from and are Distributed by that particular Contributor. A Contribution "originates" from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include changes or additions to the Program that are not Modified Works. "Contributor" means any person or entity that Distributes the Program. "Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. "Program" means the Contributions Distributed in accordance with this Agreement. "Recipient" means anyone who receives the Program under this Agreement or any Secondary License (as applicable), including Contributors. "Derivative Works" shall mean any work, whether in Source Code or other form, that is based on (or derived from) the Program and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. "Modified Works" shall mean any work in Source Code or other form that results from an addition to, deletion from, or modification of the contents of the Program, including, for purposes of clarity any new file in Source Code form that contains any contents of the Program. Modified Works shall not include works that contain only declarations, interfaces, types, classes, structures, or files of the Program solely in each case in order to link to, bind by name, or subclass the Program or Modified Works thereof. "Distribute" means the acts of a) distributing or b) making available in any manner that enables the transfer of a copy. "Source Code" means the form of a Program preferred for making modifications, including but not limited to software source code, documentation source, and configuration files. "Secondary License" means either the GNU General Public License, Version 2.0, or any later versions of that license, including any exceptions or additional permissions as identified by the initial Contributor. 2. GRANT OF RIGHTS a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, Distribute and sublicense the Contribution of such Contributor, if any, and such Derivative Works. b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in Source Code or other form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to Distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. e) Notwithstanding the terms of any Secondary License, no Contributor makes additional grants to any Recipient (other than those set forth in this Agreement) as a result of such Recipient's receipt of the Program under the terms of a Secondary License (if permitted under the terms of Section 3). 3. REQUIREMENTS 3.1 If a Contributor Distributes the Program in any form, then: a) the Program must also be made available as Source Code, in accordance with section 3.2, and the Contributor must accompany the Program with a statement that the Source Code for the Program is available under this Agreement, and informs Recipients how to obtain it in a reasonable manner on or through a medium customarily used for software exchange; and b) the Contributor may Distribute the Program under a license different than this Agreement, provided that such license: i) effectively disclaims on behalf of all other Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; ii) effectively excludes on behalf of all other Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; iii) does not attempt to limit or alter the recipients' rights in the Source Code under section 3.2; and iv) requires any subsequent distribution of the Program by any party to be under a license that satisfies the requirements of this section 3. 3.2 When the Program is Distributed as Source Code: a) it must be made available under this Agreement, or if the Program (i) is combined with other material in a separate file or files made available under a Secondary License, and (ii) the initial Contributor attached to the Source Code the notice described in Exhibit A of this Agreement, then the Program may be made available under the terms of such Secondary Licenses, and b) a copy of this Agreement must be included with each copy of the Program. 3.3 Contributors may not remove or alter any copyright, patent, trademark, attribution notices, disclaimers of warranty, or limitations of liability ("notices") contained within the Program from any copy of the Program which they Distribute, provided that Contributors may add their own appropriate notices. 4. COMMERCIAL DISTRIBUTION Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. 5. NO WARRANTY EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. 6. DISCLAIMER OF LIABILITY EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 7. GENERAL If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be Distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to Distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. Nothing in this Agreement is intended to be enforceable by any entity that is not a Contributor or Recipient. No third-party beneficiary rights are created under this Agreement. Exhibit A - Form of Secondary Licenses Notice "This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), version(s), and exceptions or additional permissions here}." Simply including a copy of this Agreement, including this Exhibit A is not sufficient to license the Source Code under Secondary Licenses. If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. You may add additional accurate notices of copyright ownership.

简介

共享使用系统内置msvcrt.dll,有效减少C/C++程序体积同时告别UCRT运行库的折磨。 展开 收起
EPL-2.0
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/Chuyu-Team/VC-LTL.git
git@gitee.com:Chuyu-Team/VC-LTL.git
Chuyu-Team
VC-LTL
VC-LTL
master

搜索帮助

F2647f8d 8189591 Bbdfb06e 8189591