User forums > Help

How to reduce the size of the executable file after compilation in CodeBlocks.

(1/2) > >>

XiloManX:
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;
}

--- End code ---

Alpha:

--- Quote from: XiloManX on February 11, 2013, 10:59:32 pm ---1. Why is it so big?

--- End quote ---
MinGW: large executables


--- Quote from: XiloManX on February 11, 2013, 10:59:32 pm ---2. How to reduce the binary to the minimum size.

--- End quote ---
There are some options listed here.  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).

XiloManX:

--- Quote from: Alpha on February 12, 2013, 02:34:10 am ---
--- Quote from: XiloManX on February 11, 2013, 10:59:32 pm ---1. Why is it so big?

--- End quote ---
MinGW: large executables
--- End quote ---
Thanks for the link to useful information.


--- Quote from: Alpha on February 12, 2013, 02:34:10 am ---
--- Quote from: XiloManX on February 11, 2013, 10:59:32 pm ---2. How to reduce the binary to the minimum size.

--- End quote ---
There are some options listed here.  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).
--- End quote ---
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)

--- End quote ---

Pecan:
You can also use an external pgm in Post build steps.

Google "upx"

XiloManX:

--- Quote from: Pecan on February 12, 2013, 02:02:12 pm ---You can also use an external pgm in Post build steps.

Google "upx"

--- End quote ---
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)

--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version