code-size.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 03 Oct 2015 18:29:10 +0300
changeset 1765 2132765de2f4
parent 279 061995ef35d2
permissions -rw-r--r--
Cellular automaton.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
-*- mode: outline; coding: utf-8 -*-
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
* Common.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
** Configuration.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
Configure build with disabling unused features e.g.:
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
  $ ./configure --without-png
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
** Link dynamically.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
Link dynamically instead statically (on your platform shared library may be
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
already present).
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
** Avoid debug build.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
Make release/final build instead debug.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
** Packer.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
Use packers. Packer compress binary so binary smaller. When program load
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
decompress itself, so startup time increase.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
  http://upx.sourceforge.net
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
                home page
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    27
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
* GCC.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
Use -Os when produce *.o files.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    31
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    32
Use -s when produce executable.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    33
And "--remove-section=.comment and --remove-section=.note".
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    35
Use:
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    37
  $ strip --strip-all <executable>
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    38
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
and
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
  $ gcc -ffunction-sections -fdata-sections -c -o my.o my.c
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
  $ gcc -Wl,--gc-sections -o my my.o
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
* MSVC.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
Use /Os when produce *.obj files.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    47