Re: Can initialization of static class members be forced before main?
On Apr 7, 12:16 pm, Carsten Fuchs <CarstenFu...@T-Online.de> wrote:
[...]
James Kanze wrote:
Are you sure you're telling the linker to incorporate all of
your modules in the final binary? (I ask, because just putting
them in a library isn't sufficient---by definition, components
in a library are only included if they resolve an unresolved
external. You have to link the .obj files themselves.
That was the crucial tip!
It really should have occured to me from the first; it seems to
be a very common error. (And let me guess that you're a bit
younger than I am.)
In hindsight, it sounds logical, but can you please tell me
where or how I can learn more about such issues?
The school of hard knocks?
Seriously, I really don't know. The linker documentation when I
was starting (e.g. for the Interdata 8/32) explained it clearly,
but most of the documentation today seems to be concerned with
which buttons to click on, rather than what you are actually
doing. The result is while it wouldn't occur to anyone of my
generation to expect files in a library to show up in the
executable unless they were explicitly mentionned, the problem
crops up regularly with younger people.
I tried before at MSDN (LINK and LIB documentation), as well
as the "Linker and Loaders" book by Levine, none of which gave
me sufficient insight though, or even a hint.
I haven't seen the "Linker and Loaders" book by Levine, but that
sort of surprises me. (The online table of contents gives a
section "Purpose of Libraries".)
I think that with the GNU linker, the command line option
--whole-archive allows me to keep the object files in a
library and still have them all included in the final binary,
even though they're not immediately required for resolving
something.
It sounds like it would do it.
Do you happen to know the equivalent for the Visual C++
linker? I've searched MSDN, but there seems to be no
equivalent linker switch?
Not off hand. I wasn't even aware of the GNU option. (Until
recently, I didn't use the GNU linker, but rather the Sun one.)
The old Intel linkers had options to force the inclusion of
specific object files from a library, but I don't remember one
for forcing them all, and of course, the Microsoft linker isn't
the old Intel one.
The solution I've usually adopted in such cases (when I wanted
to just deliver a library, and have it work as usual for the
client ) is to generate and compile a special source file
programmatically, in the makefile; this file would contain an
external reference to all of the target files, and would be
referred to explicitly in the file which managed the map. Use
of the map triggers the inclusion of the map's object file,
inclusion of the map's object file triggers inclusion of this
file, and inclusion of this file triggers inclusion of
everything else.
And the reason it works with a DLL, of course, is because
despite its name, a DLL isn't a library, but an object
file.)
Instead of "object file", you meant "(kind of) executable
file", did you?
Well, it ends up being linked into a larger executable, and it
doesn't have an entry point. But I think that under Windows,
it does behave somewhat like an executable. Under Unix, a
shared object (which isn't necessarily shared, but is
dynamically loaded), is much more like an object file, but both
have certain characteristics of object files---in particular,
they are linked into an executable as a whole.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34