c++ - fatal bug: cannot link static singleton class
This fails to link (dmc m1.cpp m2.cpp): m1.cpp: #include "single.h" int main() { X::instance(); } m2.cpp: #include "single.h" void f() { X::instance(); } single.h struct X { static void instance() { static X x; } X() {} // comment out the ctor to link successfully }; The error is: link m1+m2,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved m2.obj(m2) Offset 0011AH Record Type 0091 Error 1: Previous Definition Different : ?x ?1??instance X SAXXZ (void cdecl X::?1??inst ance::x(void )) --- errorlevel 1 Thanks, Sz.
Nov 04 2003
This one may be sort of important. I hope I'm wrong, but I found the static singleton idiom as the only solution for some cases (like a header-only implementation of a debug output controller, or default allocator instances), and I had to temporarily drop DMC support for our lib due to the problem below. Any ideas for workaround? Can I still use some kind of a "persistent" class instance (living while the process lives; i.e. some static) without adding a .cpp and losing portability? Cheers, Sz. "Luna Kid" <lunakid neuropolis.org> wrote in message news:bo9lvq$mj9$1 digitaldaemon.com...This fails to link (dmc m1.cpp m2.cpp): m1.cpp: #include "single.h" int main() { X::instance(); } m2.cpp: #include "single.h" void f() { X::instance(); } single.h struct X { static void instance() { static X x; } X() {} // comment out the ctor to link successfully }; The error is: link m1+m2,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved m2.obj(m2) Offset 0011AH Record Type 0091 Error 1: Previous Definition Different : ?x ?1??instance X SAXXZ (void cdecl X::?1??inst ance::x(void )) --- errorlevel 1 Thanks, Sz.
Nov 07 2003
Have you tried the latest beta DMC++? "Luna Kid" <lunakid neuropolis.org> wrote in message news:bog3ar$11jv$1 digitaldaemon.com...This one may be sort of important. I hope I'm wrong, but I found the static singleton idiom as the only solution for some cases (like a header-only implementation of a debug output controller, or default allocator instances), and I had to temporarily drop DMC support for our lib due to the problem below. Any ideas for workaround? Can I still use some kind of a "persistent" class instance (living while the process lives; i.e. some static) without adding a .cpp and losing portability? Cheers, Sz. "Luna Kid" <lunakid neuropolis.org> wrote in messagenews:bo9lvq$mj9$1 digitaldaemon.com...cdecl X::?1??instThis fails to link (dmc m1.cpp m2.cpp): m1.cpp: #include "single.h" int main() { X::instance(); } m2.cpp: #include "single.h" void f() { X::instance(); } single.h struct X { static void instance() { static X x; } X() {} // comment out the ctor to link successfully }; The error is: link m1+m2,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved m2.obj(m2) Offset 0011AH Record Type 0091 Error 1: Previous Definition Different : ?x ?1??instance X SAXXZ (voidance::x(void )) --- errorlevel 1 Thanks, Sz.
Nov 07 2003
Yes (after you suggested...). Same thing. Thanks, Sz. "Walter" <walter digitalmars.com> wrote in message news:bogmhh$1sf7$1 digitaldaemon.com...Have you tried the latest beta DMC++? "Luna Kid" <lunakid neuropolis.org> wrote in message news:bog3ar$11jv$1 digitaldaemon.com...This one may be sort of important. I hope I'm wrong, but I found the static singleton idiom as the only solution for some cases (like a header-only implementation of a debug output controller, or default allocator instances), and I had to temporarily drop DMC support for our lib due to the problem below. Any ideas for workaround? Can I still use some kind of a "persistent" class instance (living while the process lives; i.e. some static) without adding a .cpp and losing portability? Cheers, Sz. "Luna Kid" <lunakid neuropolis.org> wrote in messagenews:bo9lvq$mj9$1 digitaldaemon.com...cdecl X::?1??instThis fails to link (dmc m1.cpp m2.cpp): m1.cpp: #include "single.h" int main() { X::instance(); } m2.cpp: #include "single.h" void f() { X::instance(); } single.h struct X { static void instance() { static X x; } X() {} // comment out the ctor to link successfully }; The error is: link m1+m2,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved m2.obj(m2) Offset 0011AH Record Type 0091 Error 1: Previous Definition Different : ?x ?1??instance X SAXXZ (voidance::x(void )) --- errorlevel 1 Thanks, Sz.
Nov 07 2003