Author Topic: How to reduce the size of the executable file after compilation in CodeBlocks.  (Read 10576 times)

Offline XiloManX

  • Single posting newcomer
  • *
  • Posts: 4
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: [Select]
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}
« Last Edit: February 11, 2013, 11:04:26 pm by XiloManX »

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
1. Why is it so big?
MinGW: large executables

2. How to reduce the binary to the minimum size.
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).

Offline XiloManX

  • Single posting newcomer
  • *
  • Posts: 4
1. Why is it so big?
MinGW: 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.  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)
« Last Edit: February 12, 2013, 01:33:01 pm by XiloManX »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2286
You can also use an external pgm in Post build steps.

Google "upx"


Offline XiloManX

  • Single posting newcomer
  • *
  • Posts: 4
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)
« Last Edit: February 12, 2013, 03:56:09 pm by XiloManX »

Offline gd_on

  • Lives here!
  • ****
  • Posts: 590
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
Windows 10 64 bits (20.04), svn C::B (last version or almost!), wxWidgets 3.1.4, Msys2 Compilers 10.2.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (sjlj, posix in C:\msys64\mingw32).

Offline XiloManX

  • Single posting newcomer
  • *
  • Posts: 4
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
« Last Edit: February 12, 2013, 05:38:23 pm by XiloManX »