From: Andrew on 18 Mar 2010 07:52 I have a weird linktime problem that I hope people can shed some light on. This is for some code I am working on. I didn't write it. The linktime problem only happens when the library is built as a DLL. It might help when I say what the hacky workaround is that I used. There is a class that is like std::cout, used for logging. The class is a template class, the std::cout-like object is an instantiation of that class. It is declared in the header file and defined in the cpp file. The class has operator<< defined with a number of overloads. The operator<< does not depend on any template arguments so the functions are not template specialisations. The cpp file uses the cout-like object, invoking operator<< for a number of types. When the app is linked the operator<< overloads that the library itself used are found. Any use of operator<< that was not used in the library itself causes these symbols not to be found. To force the app to link I added code like this to the cpp of the library: namespace { void notUsed() { volatile bool flag = false; if (flag) { someobjecttype someobject; std::mout << someobject; } } } What is going on? I am really puzzled. FWIW, I am using Visual Studio 2008 on Windows-XP. The problem only happpens when the library is a DLL. Linking against a static version of the libary is fine. The code is not portable so I have not been able to try out building with GCC as a shared library. Regards, Andrew Marlow -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: Microsoft chooses to leave C++ compiler broken Next: Why is nullptr unsafe? |