C++ templates and visibility("hidden")

Stefan Strasser sstrasser@systemhaus-gruppe.de
Sat Apr 9 15:01:00 GMT 2005

Christian Parpart schrieb:
> Hi all,
> I'm not sure that I ran into a bug, but I'm quite sure about that -
> because the other way around just looks ugly.
> When using CXXFLAGS="-fvisibility=hidden" and declaring the following in a 
> file for a shared library:
> #define MY_API __attribute__((visibility("default")))
> template<class T>
> MY_API class U {
> public:
>     void f(T v);
> };

listen to your compiler:
c++template-visibility.h:19: warning: attribute ignored in declaration 
of 'class TFoo<T>'
c++template-visibility.h:19: warning: attribute for 'class TFoo<T>' must 
follow the 'class' keyword

and note that you can only export instantiations of templates.

Stefan Strasser

More information about the Gcc-help mailing list