0

Compiling a test module boost_program_options_test.cpp that is almost the same as boost_1_72_0\libs\program_options\example\first.cpp:

>g++ -std=c++11 -Wall -g -o boost_program_options_test.exe -ID:\temp\boostinst-01\boost_1_72_0\ -LD:\temp\boostinst-01\boost_1_72_0\stage\lib\ boost_program_options_test.cpp -lboost_program_options-mgw81-mt-x64-1_72

It compiles successfully and works but the output file is too big (using Linux utils in Windows):

>du boost_program_options_test.exe -h
1,9M    boost_program_options_test.exe

2M is really too much for just CLI parameters parsing! Please help me reduce the output to a reasonable size.

EDITED:

As people in the answers suggested did the following:

  • switched off debug information (-g)
  • switched on optimization (-O2)
  • stripped the executable (using binutils from mimgw64 distribution)

That's what I get:

g++ -std=c++11 -Wall  -g -o boost_program_options_test.exe -ID:\temp\boostinst-01\boost_1_72_0\ -LD:\temp\boostinst-01\boost_1_72_0stage\lib\ boost_program_options_test.cpp -lboost_program_options-mgw81-mt-x64-1_72
dir | find "boost_program_options_test.exe"
20.04.2020  09:56         1 950 374 boost_program_options_test.exe

g++ -std=c++11 -Wall  -o boost_program_options_test.exe -ID:\temp\boostinst-01\boost_1_72_0\ -LD:\temp\boostinst-01\boost_1_72_0\stage\lib\ boost_program_options_test.cpp -lboost_program_options-mgw81-mt-x64-1_72
dir | find "boost_program_options_test.exe"
20.04.2020  09:56         1 115 710 boost_program_options_test.exe

g++ -std=c++11 -Wall  -O2 -o boost_program_options_test.exe -ID:\temp\boostinst-01\boost_1_72_0\ -LD:\temp\boostinst-01\boost_1_72_0\stage\lib\ boost_program_options_test.cpp -lboost_program_options-mgw81-mt-x64-1_72
dir | find "boost_program_options_test.exe"
20.04.2020  09:56           753 051 boost_program_options_test.exe

strip --strip-all boost_program_options_test.exe
dir | find "boost_program_options_test.exe"
20.04.2020  09:56           293 888 boost_program_options_test.exe

Thanks guys!

Nick Legend
  • 789
  • 1
  • 7
  • 21
  • 2
    turn off the debugging information (`-g`) and enable optimisations (`-O2`). Heavily templated code (like a lot of the boost libraries) simply produces large executables its nothing to worry about – Alan Birtles Apr 19 '20 at 09:45
  • see also https://stackoverflow.com/questions/1540523/strip-executable-windows – Alan Birtles Apr 19 '20 at 09:47
  • I believe there isn't anything shocking about that. Actually the problem is that boost headers include a lot of libraries which result in high program size. You can use g++ optimization levels to reduce size to an extent. Also checkout this thread: https://stackoverflow.com/questions/1042773/gcc-c-hello-world-program-exe-is-500kb-big-when-compiled-on-windows-how . – brc-dd Apr 19 '20 at 09:48
  • @DivyanshSingh A simple [program](https://stackoverflow.com/a/61296187/85371) builds a 21MiB binary, `strip`-ping the debug info leaves 311kb (nice link though, this might prove helpful to the OP) – sehe Apr 19 '20 at 20:38
  • Do `readelf -WS `, it shows how many bytes each section occupies in `Size` column - no guesswork required. – Maxim Egorushkin Apr 20 '20 at 09:24
  • @Maxim Egorushkin It says: `readelf: Error: Not an ELF file - it has the wrong magic bytes at the start` – Nick Legend Apr 20 '20 at 10:56

0 Answers0