Linker strips too much
Michael Greminger -- michael.greminger@dial.eunet.ch Wednesday, July 03, 1996 Environment VC4.1, NT4.0 beta2 I have a serious problem. I created two macros in my project: #define DECLARE_HI \ virtual CString GetName(); \ virtual long GetID(); \ #define IMPLEMENT_HI(class_name, id, name, long_name) \ CHI* class_name##Creator(short side) { return (new class_name(side)); } \ static CHIDesc foo(id, name, long_name, class_name##Creator); \ CString class_name::GetName() { return name;} \ long class_name::GetID() { return id; } These two macros appear in the header and the implementation of class, for example class CFoo : public CFoo2 { public: DECLARE_SERIAL( CFoo ) DECLARE_HI and in the implementation file IMPLEMENT_HI(CFoo , 17, "Foo", "Long foo") As you can see in the IMPLEMENT_HI macro there is a "static CHIDesc foo" where the constructor should be executed at start time. All works fine but when put these classes in a library the constructor is not called !! I suppose that the linker sees no reference to this class so it removes everything. When I add some explicit references to this class anywhere in my code (for example CFoo* foo = new CFoo; delete foo;) everythins works fine again. Is there a solution for this problem, so that the constructor is also called if the class is in a library. Michael
Niels Ull Jacobsen -- nuj@kruger.dk Wednesday, July 10, 1996 At 08:14 03-07-96 +0200, you wrote: >Environment VC4.1, NT4.0 beta2 > >I have a serious problem. > >I created two macros in my project: > >#define DECLARE_HI \ > virtual CString GetName(); \ > virtual long GetID(); \ > >#define IMPLEMENT_HI(class_name, id, name, long_name) \ > CHI* class_name##Creator(short side) { return (new class_name(side)); } \ > static CHIDesc foo(id, name, long_name, class_name##Creator); \ > CString class_name::GetName() { return name;} \ > long class_name::GetID() { return id; } > >These two macros appear in the header and the implementation of class, f= or example > >class CFoo : public CFoo2 >{ >public: > DECLARE_SERIAL( CFoo ) > DECLARE_HI > > >and in the implementation file > >IMPLEMENT_HI(CFoo , 17, "Foo", "Long foo") > >As you can see in the IMPLEMENT_HI macro there is a "static CHIDesc >foo" where the constructor should be executed at start time. All works >fine but when put these classes in a library the constructor is not >called !! I suppose that the linker sees no reference to this class so >it removes everything. When I add some explicit references to this >class anywhere in my code (for example CFoo* foo =3D new CFoo; delete >foo;) everythins works fine again. > >Is there a solution for this problem, so that the constructor is also >called if the class is in a library. A probable work-around would be to use the "Force Symbol References" in the link settings (/INCLUDE:symbol). You would have to use the decorated=20 name of CHiDesc::CHiDesc, gotten from the map file. =20 >Michael Niels Ull Jacobsen, Kr=FCger A/S (nuj@kruger.dk) Everything stated herein is THE OFFICIAL POLICY of the entire Kruger=20 group and should be taken as legally binding in every respect.=20 Pigs will grow wings and fly.
| Вернуться в корень Архива |