 <p>You want the <a href="http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#Function-Attributes" rel="nofollow">visibility attribute</a> extension of GCC.</p> <p>Practically, something like:</p> <pre><code> #define MODULE_VISIBILITY __attribute__ ((visibility ("hidden"))) #define PUBLIC_VISIBILITY __attribute__ ((visibility ("default"))) </code></pre> <p><sup>(You probably want to <code>#ifdef</code> the above macros, using some configuration tricks à la <code>autoconf</code>and other <em>autotools</em>; on other systems you would just have empty definitions like <code>#define PUBLIC_VISIBILITY /*empty*/</code> etc...)</sup></p> <p>Then, declare a variable:</p> <pre><code>int module_var MODULE_VISIBILITY; </code></pre> <p>or a function </p> <pre><code>void module_function (int) MODULE_VISIBILITY; </code></pre> <p>Then you can use <code>module_var</code> or call <code>module_function</code> inside your shared library, but not outside.</p> <p>See also the <a href="http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html" rel="nofollow">-fvisibility</a> code generation option of GCC.</p> <p>BTW, you could also compile your whole library with <code>-Dsomeglobal=alongname3419a6</code> and use <code>someglobal</code> as usual; to really find it your user would need to pass the same preprocessor definition to the compiler, and you can make the name <code>alongname3419a6</code> random and improbable enough to make the collision improbable.</p> <hr> <p>PS. This visibility is <strong>specific to GCC</strong> (and probably <strong>to ELF shared libraries</strong> such as those on Linux). It won't work without GCC or outside of shared libraries.... so is quite Linux specific (even if some few other systems, perhaps Solaris with GCC, have it). Probably some other compilers (<code>clang</code> from <a href="http://llvm.org/" rel="nofollow">LLVM</a>) might support also that <em>on Linux</em> for <em>shared libraries</em> (not static ones). Actually, the real hiding (to the several compilation units of a single shared library) is done mostly by the linker (because the <a href="http://en.wikipedia.org/wiki/Executable_&amp;_Linkable_Format" rel="nofollow">ELF</a> shared libraries permit that).</p>