BUG: C2487 Error Occurs If Multiple Static Vars Use dllexport

Last reviewed: July 24, 1997
Article ID: Q127900
The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1, 4.0, 4.1,

         4.2, 5.0
    

SYMPTOMS

Using _declspec(dllexport) or _declspec(dllimport) on a class with multiple static variable definitions may cause a C2487 error to be generated on all but the first variable. For example, consider this class declaration:

   class _declspec(dllexport) MyClass
   {
   public:
     static int i,j,k;
   };

This class declaration generates these errors:

   error C2487: 'j' : member of dll interface class may not be declared
                      with dll interface
   error C2487: 'k' : member of dll interface class may not be declared
                      with dll interface

RESOLUTION

Move each static variable declaration to its own line. To fix the above class so that it will compile cleanly, use this:

   class _declspec(dllexport) MyClass
   {
   public:
     static int i;
     static int j;
     static int k;
   };

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


Additional query words: dllimport export afxdll 9.00 9.10 10.00 10.10 10.20
Keywords : CPPLngIss vcbuglist400 vcbuglist500
Version : 2.0 2.1 4.0 4.1 4.2 5.0
Platform : NT WINDOWS
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.