title: How to properly set the visibility property in CMake with gcc?
body: <p>I tried a couple of options to properly set the visibility in my library. Like:</p>
  
  <pre><code>target_compile_options(MY_LIB PRIVATE "-fvisibility=hidden")
  set_target_properties(MY_LIB PROPERTIES C_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
  set_target_properties(MY_LIB PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
  </code></pre>
  
  <p>And both don't work. I have the specific functions that I want to expose set inside a block</p>
  
  <pre><code>#pragma GCC visibilty push(default)
    void thisShouldBeTheOnlyThingVisible(void) {
      ...
    }
  #pragma GCC visibilty pop
  </code></pre>
  
  <p>But, if I run different tools, like <em>objdump</em> or <em>readelf</em>, not only I'm seeing all the internal functions that should not be listed, I also see file names and non static variable names. I wouldn't mind in <em>debug</em> mode, but in <em>release</em>, it shouldn't be there.</p>
  
  <p>What's the right process here to get everything that I want hidden except those special functions?</p>
  
  <p>Thanks</p>
  
  <p>W</p>