Code::Blocks Forums

User forums => Help => Topic started by: XiloManX on February 11, 2013, 10:59:32 pm

Title: How to reduce the size of the executable file after compilation in CodeBlocks.
Post by: XiloManX on February 11, 2013, 10:59:32 pm
I started to learn C + +. I use CodeBlocks in Windows. I noticed that after compilation, is a file size of 467kB (release) and 943kB (debug).But the executable should be much less.

So I have two questions:
1. Why is it so big?
2. How to reduce the binary to the minimum size.

A simple example that when compiled in CodeBlocks get enormous size.
Code
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}
Title: Re: How to reduce the size of the executable file after compilation in CodeBlocks.
Post by: Alpha on February 12, 2013, 02:34:10 am
1. Why is it so big?
MinGW: large executables (http://mingw.org/wiki/Large_executables)

2. How to reduce the binary to the minimum size.
There are some options listed here (http://wiki.codeblocks.org/index.php?title=Creating_a_new_project#Adding_a_new_build_target).  Keep in mind that many compiler flags can have other effects (for example, static vs. dynamic runtime libraries), so read documentation to understand what they do.  If something does not make sense, try Google (it does not bite).
Title: Re: How to reduce the size of the executable file after compilation in CodeBlocks.
Post by: XiloManX on February 12, 2013, 01:26:47 pm
1. Why is it so big?
MinGW: large executables (http://mingw.org/wiki/Large_executables)
Thanks for the link to useful information.

2. How to reduce the binary to the minimum size.
There are some options listed here (http://wiki.codeblocks.org/index.php?title=Creating_a_new_project#Adding_a_new_build_target).  Keep in mind that many compiler flags can have other effects (for example, static vs. dynamic runtime libraries), so read documentation to understand what they do.  If something does not make sense, try Google (it does not bite).
Did everything as written, but does not collect CodeBlocks project. What is wrong? Build log is attached (Code::Blocks v12.11).

Quote
-------------- Build: Release Small in First (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe  -o bin\ReleaseSmall\First.exe obj\ReleaseSmall\main.o   -s -flto -Os -Wl,--gc-sections -shared-libgcc -shared-libstdc++  
c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe: c:/program: error loading plugin
collect2.exe: error: ld returned 1 exit status
c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe: c:/program: error in plugin cleanup (ignored)
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)
Title: Re: How to reduce the size of the executable file after compilation in CodeBlocks.
Post by: Pecan on February 12, 2013, 02:02:12 pm
You can also use an external pgm in Post build steps.

Google "upx"

Title: Re: How to reduce the size of the executable file after compilation in CodeBlocks.
Post by: XiloManX on February 12, 2013, 03:52:12 pm
You can also use an external pgm in Post build steps.

Google "upx"
Thank you. But I'm more interested in the question of why is not going to my project. What's the error and how to fix it?

Quote
-------------- Build: Release Small in First (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe  -o bin\ReleaseSmall\First.exe obj\ReleaseSmall\main.o   -s -flto -Os -Wl,--gc-sections -shared-libgcc -shared-libstdc++  
c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe: c:/program: error loading plugin
collect2.exe: error: ld returned 1 exit status
c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe: c:/program: error in plugin cleanup (ignored)
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)
Title: Re: How to reduce the size of the executable file after compilation in CodeBlocks.
Post by: gd_on on February 12, 2013, 04:39:31 pm
I see in your messages c:/program: error ....
This suggest me that one of the mingw tools used still consider a blank space as a string separator. So the full name c:/program files/... is not accessible, because the real full name is truncated.
Try to install your compiler in a path without any space in its full name.
I know that the standard mingw compiler installed with C::B installs the compiler within a sub folder of "program files/codeblocks". Generally, it works, but for some tools, it apparently still has problems. A solution : download the tdm compiler and install it directly in c:\Mingw32 (or c:\MinGW64) and rebuild the compiler and link path in your C::B configuration.
May be you can also try a simple copy (or move) of the mingw subfolder of codeblocks (and always update the path cofiguration).

gd_on
Title: Re: How to reduce the size of the executable file after compilation in CodeBlocks.
Post by: XiloManX on February 12, 2013, 05:30:34 pm
gd_on Hooray, everything works.  :) Thanks for the explanation and help.
Alpha Thanks you for the help, too.

The question is closed.  Everything works fine.  :) :D ;D