title: Link static member from dll
body: <p>I've a strange problem with linking a static member from a dll using Visual Studio Express 2010. On Linux platform
  and MSYS/MinGW (GCC) this failure doesn't occurs.</p>
  
  <p>I've a Math library using an export macro explicitly for this library module:</p>
  
  <pre><code>#ifdef WIN32
    #ifdef MATH_LIBRARY_EXPORT
      #define MATH_LIBRARY_API __declspec(dllexport)
    #else
     #define MATH_LIBRARY_API __declspec(dllimport)
    #endif
  #else
    //define empty values for linux OS
    #define MATH_LIBRARY_API
  #endif
  </code></pre>
  
  <p>And this is a snipped of my Vector class i export with static members:</p>
  
  <pre><code>ifndef BINREV_VECTOR_H__
  #define BINREV_VECTOR_H__
  
  // include common header with dll import/export macro
  #include &lt;brMath/brCommons.h&gt;
  
  namespace binrev{
  namespace brMath{
  
  class MATH_LIBRARY_API brVector3f
  {  
    public:
    float m_fX, m_fY, m_fZ;
  
    brVector3f(void);
    brVector3f(float x, float y, float z);
  
    ...
  
    public:
    static const brVector3f ZERO;
    static const brVector3f NEGATIVE_UNIT_Z;
    ...
  };
  </code></pre>
  
  <p>And the cpp module:</p>
  
  <pre><code>// Ensure that the dll hader will be exported
  #define MATH_LIBRARY_EXPORT
  #include &lt;brMath/brVector3f.h&gt;
  
  namespace binrev{
  namespace brMath{
  
  const brVector3f brVector3f::ZERO(0.0f, 0.0f, 0.0f);
  const brVector3f brVector3f::NEGATIVE_UNIT_Z( 0.0f, 0.0f, -1.0f);
  
  ...
  </code></pre>
  
  <p>In my Graphics module (is also an dll with an different explicit export macro) using this Math dll i try to access one of those static members:</p>
  
  <pre><code>#include &lt;brMath/brVector3f.h&gt;
  
  brMath::brVector3f brCamera::getDirection(void)
  {
     return  m_orientation.rotate(brMath::brVector3f::NEGATIVE_UNIT_Z);
  }
  </code></pre>
  
  <p>On the other platforms anything works well, but with MVSE 2010 i got
  a linker failure:</p>
  
  <pre><code>1&gt;------ Erstellen gestartet: Projekt: ZERO_CHECK, Konfiguration: Debug Win32 ------
  2&gt;------ Erstellen gestartet: Projekt: brGraphics, Konfiguration: Debug Win32 ------
  2&gt;  brCamera.cpp
  2&gt;brCamera.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: static   class binrev::brMath::brVector3f const binrev::brMath::brVector3f::NEGATIVE_UNIT_Z"  (?NEGATIVE_UNIT_Z@brVector3f@brMath@binrev@@2V123@B)".
  2&gt;C:\binrev\repository\binrevengine\modules\brGraphics\trunk\bin\brGraphics.dll : fatal error LNK1120: 1 nicht aufgelöste externe Verweise.
  ========== Erstellen: 1 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
  </code></pre>
  
  <p>I'm not a friend of MVSE and this are my first tries to get our code runable with MVSE. While I've different solutions I've add the brMath.lib as additional dependency at the project settings. I've also set the path of the additional library directory to the location of my brMath.lib. This is the output of the linker command for review of my settings:</p>
  
  <pre><code>/OUT:"C:\binrev\repository\binrevengine\modules\brGraphics\trunk\bin\brGraphics.dll"    /INCREMENTAL /NOLOGO
  /LIBPATH:"C:\binrev\repository\binrevengine\modules\brMath\trunk\lib\Debug" /DLL   "kernel32.lib" "user32.lib" "gdi32.lib"
  "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib"    "advapi32.lib" "brCore.lib" "brMath.lib"
  "c:\binrev\development\vs2010\VC\lib\libboost_signals-vc100-mt-gd-1_47.lib" "c:\binrev \development\vs2010\VC\lib\libboost_system-vc100-mt-gd-1_47.lib"
  /MANIFEST /ManifestFile:"brGraphics.dir\Debug\brGraphics.dll.intermediate.manifest"   /ALLOWISOLATION
  /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\binrev\repository  \binrevengine\modules\brGraphics\trunk\bin\brGraphics.pdb"
  /SUBSYSTEM:CONSOLE /STACK:"10000000" /PGD:"C:\binrev\repository\binrevengine\modules\brGraphics\trunk\bin\brGraphics.pgd" /TLBID:1
  /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/binrev/repository/binrevengine/modules/brGraphics  /trunk/lib/Debug/brGraphics.lib" /MACHINE:X86 /ERRORREPORT:QUEUE
  </code></pre>
  
  <p>It seems too me that anything is linked correctly. When I remove the call of the const static dll member of brVector3f the build is successfull. I think there must be a problem with the const static member. But why in hell only with MVSE ?</p>
  
  <p>I couldn't find any difference to this introducion: <a href="http://stackoverflow...c-data-in-a-dll" rel="nofollow">http://stackoverflow...c-data-in-a-dll</a>
  So it normally should be working ... </p>
  
  <p>Now i running out of ideas what could be wrong.
  I'm grateful for any help or hint.</p>