473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

will linker leave out unused symbols from binary?

Hi,

I'm thinking about whether or not to build a general library on its own and
later link that lib with the main executable, or to build the main
executable with a subset of the relevant source files from that library.

If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions that
are never used.

But I do not like to manage this kind of dependency! I'd much rather just
build a lib with all files that belongs to that module and later link
against that library when producing the exe. Separations of concern and easy
management of dependicies :-)

However, I'm not sure if this may lead to an undesired increase of the
executable's size (since unused symbols and functions may get linked in into
the executable). What is the story about this?

I know that this must be an implementation issue, i.e. it is up to the
linker to leave unused stuff out of the exe - but I hope that there is a
general answer :-)

Thanks in advance!

Jul 22 '05 #1
4 2281

"Sam Smith" <sa*@smith.com> wrote in message
news:%m****************@nntpserver.swip.net...
Hi,

I'm thinking about whether or not to build a general library on its own and later link that lib with the main executable, or to build the main
executable with a subset of the relevant source files from that library.

If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions that are never used.

But I do not like to manage this kind of dependency! I'd much rather just
build a lib with all files that belongs to that module and later link
against that library when producing the exe. Separations of concern and easy management of dependicies :-)

However, I'm not sure if this may lead to an undesired increase of the
executable's size (since unused symbols and functions may get linked in into the executable). What is the story about this?

I know that this must be an implementation issue, i.e. it is up to the
linker to leave unused stuff out of the exe - but I hope that there is a
general answer :-)


The general answer is that it is an implementation issue. Consult your
linker documentation. Maybe even do some experiments.

Incidentally this question has very little to do with C++ which is what this
group is supposed to be about.

john
Jul 22 '05 #2
Sam Smith wrote:
I'm thinking about whether or not to build a general library on its own and
later link that lib with the main executable, or to build the main
executable with a subset of the relevant source files from that library.

If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions that
are never used.

But I do not like to manage this kind of dependency! I'd much rather just
build a lib with all files that belongs to that module and later link
against that library when producing the exe. Separations of concern and easy
management of dependicies :-)

However, I'm not sure if this may lead to an undesired increase of the
executable's size (since unused symbols and functions may get linked in into
the executable). What is the story about this?

I know that this must be an implementation issue, i.e. it is up to the
linker to leave unused stuff out of the exe - but I hope that there is a
general answer :-)


There is no general answer, not in terms of Standard C++ language, anyway.
Linkers are OS-dependent, compiler-dependent, and differ from vendor to
vendor. Some are smarter, some are dumber. All we can tell you that you
are right to _want_ this, but there is no guarantee to get it.

V
Jul 22 '05 #3
On Tue, 28 Sep 2004 16:16:45 +0200 in comp.lang.c++, "Sam Smith"
<sa*@smith.com> wrote,
If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions that
are never used.


A typical common behavior is that the linker will pull out of the
library any object file that is needed to satisfy a reference, and leave
out any object file that is completely unused, but it cannot split up
any object file and bring in part of it. For best results the library
must be built out of many small object files each containing the
smallest working subset of mutually dependent code and data.

Of course this is outside the scope of the C++ language and you must
read the fine manual of your particular implementation.

Jul 22 '05 #4
Sam Smith wrote:
Hi,

I'm thinking about whether or not to build a general library on its own and
later link that lib with the main executable, or to build the main
executable with a subset of the relevant source files from that library.

If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions that
are never used.

But I do not like to manage this kind of dependency! I'd much rather just
build a lib with all files that belongs to that module and later link
against that library when producing the exe. Separations of concern and easy
management of dependicies :-)

However, I'm not sure if this may lead to an undesired increase of the
executable's size (since unused symbols and functions may get linked in into
the executable). What is the story about this?

I know that this must be an implementation issue, i.e. it is up to the
linker to leave unused stuff out of the exe - but I hope that there is a
general answer :-)

There is not.

On e.g. GNU/Linux, if you create a (static archive/library)
every object file as a whole is either included or not.
That is, if something is needed in a .o file, the whole .o
file is linked in, otherwise it is left out. This seems
rather common among other implmentations as well though.
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rebecca Hoffmann | last post by:
Hi, I have a serious problem while compiling a small project (a part of the Modular Flow Scheduling Middleware: ex1): There are 3 linker errors, all from symbols that point to templates: --...
1
by: Srikanth Madani | last post by:
Hi all, Suppose I have a C file fun1.c containing two functions: __________ void func1() { printf("\nIn function func1()\n"); } void func2() { func3(); }
9
by: Felix Kater | last post by:
Hi, if I link my code to other o-files: Does the linker include the whole o-file or does it use the needed functions from that only? Felix
1
by: Lynn McGuire | last post by:
How do I get a list of unused functions in my application using Visual C++ 2003 ? I know that I have several in 300,000 lines of C++ code. However, tracking them down is very difficult. ...
4
by: Joel Whitehouse | last post by:
Hello All, I have a Visual C++ 2003 dll solution in a directory called "Antenna Test Range Control", and when I comile it, I get the error LNK1104: cannot open file "antenna.obj". When I remove...
3
by: ralphsieminsky | last post by:
A project compiles fine under VS 2005 RC without the /clr option. However, when /clr is turned on several errors appear: - A symbol exported from a DLL is not found by another DLL referencing...
0
by: VivekR | last post by:
I have a MFC application developed using VC++ 5. Recently I ported that to VC++ 7.1 and now I am trying to compile the MFC application with /CLR under VC++ 7.1. And I get linker errors referring to...
1
by: ImamicPH | last post by:
Hi, My first post. How do you resolve linker errors? I have a simple header file that contains one function declaration. This function is used in another file (.cpp) in the definition of a...
2
by: Oneironaut | last post by:
Hello friends, I have an issue with a linker warning. It is the warning LNK4089. I am working in MSVC6.0 I investigated and this warning tells that the import of the library to which it makes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.