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

LVL 1
alex1234Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.