From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Buck To: martin@mira.isdn.cs.tu-berlin.de (Martin v. Loewis) Cc: Theodore.Papadopoulo@sophia.inria.fr, gcc@gcc.gnu.org Subject: Re: C++ and static data members... Date: Thu, 02 Sep 1999 16:36:00 -0000 Message-id: <199909022335.QAA23217@atrus.synopsys.com> References: <199909022320.BAA00854@mira.isdn.cs.tu-berlin.de> X-SW-Source: 1999-09/msg00100.html Martin Loewis writes: > Well, you are missing an implementation restriction. You must not put > the object files containing such globals in a library. Instead, you > must pass them to the linking command line explicitly. > > This is because of the way the linker works: it won't use object files > from a library unless they are used. That last sentence is not very clear. What actually happens is that the linker processes files and libraries on the command line left to right. It will not select an object file from a library unless that object file defines a global symbol that is currently undefined. To oversimplify things a bit, initially only the symbol "main" is undefined (really it's a bit different: a startup function is chosen which calls main, but it gives you a picture of what's going on). If you want to be sure that a particular static object is included, you can make sure that the .o file that contains it also defines some global symbol that is referenced by some other file that must be included. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Buck To: martin@mira.isdn.cs.tu-berlin.de (Martin v. Loewis) Cc: Theodore.Papadopoulo@sophia.inria.fr, gcc@gcc.gnu.org Subject: Re: C++ and static data members... Date: Thu, 30 Sep 1999 18:02:00 -0000 Message-ID: <199909022335.QAA23217@atrus.synopsys.com> References: <199909022320.BAA00854@mira.isdn.cs.tu-berlin.de> X-SW-Source: 1999-09n/msg00100.html Message-ID: <19990930180200.1VNvL9lGjun7IkYhqc9gDahNVWLHP32ycYkX46_hrrw@z> Martin Loewis writes: > Well, you are missing an implementation restriction. You must not put > the object files containing such globals in a library. Instead, you > must pass them to the linking command line explicitly. > > This is because of the way the linker works: it won't use object files > from a library unless they are used. That last sentence is not very clear. What actually happens is that the linker processes files and libraries on the command line left to right. It will not select an object file from a library unless that object file defines a global symbol that is currently undefined. To oversimplify things a bit, initially only the symbol "main" is undefined (really it's a bit different: a startup function is chosen which calls main, but it gives you a picture of what's going on). If you want to be sure that a particular static object is included, you can make sure that the .o file that contains it also defines some global symbol that is referenced by some other file that must be included.