杨庆荣的博客

工作之余接单:公司产品展示网站建设、电商网站建设、小程序、app开发。+86 13714715608

TDM-GCC编译后exe文件太大了,这里有缩小的方法

点击 551    创建时间 2016-07-21 18:09:04

<p>原创文章,免费转载请注明出处。http://wudimei.com/yangqingrong<br /> 我在TDM-GCC官网上看到这一段话:“TDM-GCC still includes DLL versions of the libgcc and libstdc++ runtimes, which you can enable for your program with "-shared-libgcc" and "-shared-libstdc++" if desired.”</p>

<p>意思是说TDM-GCC仍然包含libgcc和libstdc++运行时的DLL版本(默认不使用动态DLL),如果需要,你可以为你的程序启用它,使用"-shared-libgcc" 和"-shared-libstdc++" 参数。</p>

<p> </p>

<p>于是我试了一下:</p>

<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">g++ test.cpp -m32 -s -shared-libstdc++ -fno-exceptions -flto -fno-rtti -Os</div>

<p>结果编译后的a.exe只有12kb大小。</p>

<p><strong>参数说明</strong></p>

<p>-s 剪去符号。<br /> -m32 这是输出32位的程序<br /> -shared-libstdc++ 链接c++动态链接库,发布时要带上DLL。如果是gcc就使用"-shared-libgcc"<br /> -fno-exceptions 不要异常</p>

<p><strong>test.cpp内容</strong></p>

<p>#include<br />

include</p>

<p>using namespace std;<br /> class Person{<br />   public:<br />   int id;<br />   void setId(int newId){<br />       this-&gt;id =newId;<br />   }<br />   int getId(){<br />       return this-&gt;id;<br />   }<br /> };<br />  <br /> int main(int argc, char **argv)<br /> {<br />     Person p;<br />     p.id=10;<br />     p.setId( 1024);<br />     printf("hello world! persion id: %d;\n", p.getId() );<br />      cout&lt;     <br /> }</p>

<p> </p>

上一篇: bootstrap overflow-y:hidden造成下拉菜单被隐藏
下一篇: 104: Connection reset by peer