Discussion:
Linking with static libs built with MinGW
(too old to reply)
Igor R.
2010-01-06 20:03:16 UTC
Permalink
Hello,

I noticed that when I link my application with static libraries built
with MinGW/gcc (like ffmpeg), the apllication size is increased by the
size of these libraries - even though I don't use most of their code.
To verify this guess, I reconfingured and rebuilt the libs, excluding
a lot of unused features - the libs became smaller, and the
application size decreased drastically.
I link in MSVC9.0 in release mode, with /OPT:REF /OPT:ICF.

So is there a way to make the linker drop unused code in this case?
Carl Daniel [VC++ MVP]
2010-01-07 15:12:23 UTC
Permalink
Post by Igor R.
Hello,
I noticed that when I link my application with static libraries built
with MinGW/gcc (like ffmpeg), the apllication size is increased by the
size of these libraries - even though I don't use most of their code.
To verify this guess, I reconfingured and rebuilt the libs, excluding
a lot of unused features - the libs became smaller, and the
application size decreased drastically.
I link in MSVC9.0 in release mode, with /OPT:REF /OPT:ICF.
So is there a way to make the linker drop unused code in this case?
Two options:

1. The libraries are not properly constructed libraries and the linker is
unable to separate the modules. This seems unlikely.

2. Something about your linker command or the files is causing the linker to
treat these libraries as object files and not as libraries.

I'd suggest linking with /verbose and studying the output for clues.

-cd
sasha
2010-01-07 19:48:58 UTC
Permalink
Post by Carl Daniel [VC++ MVP]
1. The libraries are not properly constructed libraries and the linker
is unable to separate the modules. This seems unlikely.
Function-level linking wasn't enabled?
Post by Carl Daniel [VC++ MVP]
2. Something about your linker command or the files is causing the
linker to treat these libraries as object files and not as libraries.
That shouldn't make a difference, I don't think.
Igor R.
2010-01-07 21:15:18 UTC
Permalink
The libraries have *.a extenstion, but I don't think this matters.
Post by sasha
Function-level linking wasn't enabled?
Yes, it seems to be something like this. In there such an option in
MinGW/gcc - like /Gy in MSVC? (Well, I know it's better to ask in an
appropriate group, but maybe one of you has the relevant experience.)
sasha
2010-01-07 22:12:40 UTC
Permalink
Post by Igor R.
Yes, it seems to be something like this. In there such an option in
MinGW/gcc - like /Gy in MSVC? (Well, I know it's better to ask in an
appropriate group, but maybe one of you has the relevant experience.)
I'm not familiar with that, sorry.
Igor R.
2010-01-07 23:01:33 UTC
Permalink
It seems that --extra-cflags="-ffunction-sections -fdata-sections" are
expected to do the job.

Loading...