Hiding instantiated templates in shared library created with g++

前端 未结 5 888
终归单人心
终归单人心 2020-12-17 14:59

I have a file that contains the following:

#include 

class A {};

void doSomething() {
   std::map m;
}

When comp

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-17 15:29

    In C++, if a template argument has limited visibility, this restriction is implicitly propagated to the template instantiation.

    #include 
    
    class __attribute__((visibility ("hidden"))) A {};
    
    void doSomething() {
      std::map m;
    }
    

    should do the job.

    -- edit --
    One more thing, `#pragma GCC visibility' affects only namespace-scope declarations. Class members and template specializations are not affected (Visibility pragmas)

提交回复
热议问题