How to create a variable that library code can use and a user can set? : <p>1) I want to use variable <code>n_threads</code> inside my library code (that is distributed in shared library form on Windows and Linux) in multiple <code>.cpp</code> files.</p>

<p>2) I want to make library user to set it. </p>

<p>How to do such thing in C++?</p>

<ul>
<li>I tried global file with <code>static</code> variables - it leads to each <code>.cpp</code> file having its copy; </li>
<li>I have tried just to keep it in a namespace which leads to variable being already defined in other translation units and thus library not compiling</li>
<li>I have tried <code>external</code> (which works on Linux with <code>.so</code> and does compile on Windows MSVC14) which leads to library not compiling due to unresolved externals.</li>
</ul>

<p>What can be done to make global variable used in multiple library <code>.cpp</code> files be setable from outside (from library user code)?</p>
