------- Additional Comments From jmegq at radiance dot com 2005-09-02 00:16 ------- Regarding macros -- I just found out about the _Pragma directive from C99, so at least you can do something like this (paraphrasing some ACE code):
#define EXPORT_SINGLETON_DECLARE (SINGLETON_TYPE, CLASS, LOCK) \ _Pragma ("GCC visibility push(default)") \ template class SINGLETON_TYPE <CLASS, LOCK>; \ _Pragma ("GCC visibility pop") #define IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) extern template class SINGLETON_TYPE <CLASS, LOCK>; Then define SINGLETON_DECLARE to depending on whether you're building the lib or not. A possible issue with this is that it must come before, say, a typedef of the template type. The example below works on VS but not g++ (not that VS matters, but I'm using code that does this): typedef Singleton_T<Foo, Mutex> FOO_SINGLETON; SINGLETON_DECLARE(Singleton_T, Foo, Mutex) Instead, the SINGLETON_DECLARE needs to come before the typedef or it will get hidden visibility on g++. I'm curious as to why the typedef causes the symbols to get hidden visibility -- is that in spec, or is a bug? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470