• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1961
  • Last Modified:

To export a constant from DLL

How to export a constant from DLL? I have

__declspec(dllexport) const int aaa = 1;

and I get error C2201: 'aaa' : must have external linkage in order to be exported/imported

or

error LNK2005: "int const  aaa" (?yy@@3HB) already defined in Stdafx.obj

0
alex1234
Asked:
alex1234
  • 7
1 Solution
 
WynCommented:
Read this from MSDN:
the Knowledge Base article “Exporting Data from a DLL or an Application” (Q90530).
0
 
WynCommented:
Wyn changed their proposed answer to a comment
0
 
WynCommented:
In C, constant values default to external linkage, so they can appear only in source files. In C++, constant values default to internal linkage, which allows them to appear in header files.

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
WynCommented:
In C, constant values default to external linkage, so they can appear only in source files. In C++, constant values default to internal linkage, which allows them to appear in header files.

0
 
WynCommented:
But identifer must have external linkage in order to be exported/imported.
0
 
WynCommented:
Try to add extern to it.
0
 
WynCommented:
like:
__declspec(dllexport) extern const int aaa = 1 ;
0
 
alex1234Author Commented:
Wyn,

I've already figured it out: __declspec(dllexport) extern const int aaa = 1 ; works if it is declared in *.CPP - I had it declared in *.H.

Thanks anyway...


0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now