This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Exporting const variables from DLLs (GCC bug?)


Hi,

Given this source code:
extern const int meaning_of_life __declspec(dllexport);
const int meaning_of_life __declspec(dllexport) = 42;

GCC complains:
$ c++ -g -O2 -c test.cxx -o test.o
test.cxx:2: error: external linkage required for symbol 'const int
   meaning_of_life' because of 'dllexport' attribute.

However, it compiles successfully with the "const" qualifier removed:
extern int meaning_of_life __declspec(dllexport);
int meaning_of_life __declspec(dllexport) = 42;

Why does adding the "const" qualifier change this? Is this a known limitation of DLLs? If so, the error message is a little confusing. If not, then this is a GCC bug.

Removing the explicit "extern" line has no effect in either
case.

My Cygwin installation was updated recently - I'm using the
standard Cygwin GCC 3.3.1-3 package:
$ c++ --version
c++ (GCC) 3.3.1 (cygming special)

If you want any more info, just ask.


Incidentally, this bug affects src/sid/component/ in the
Cygwin CVS tree.  I'd prepared this minimal test case before
I realized that this subdirectory isn't needed to build the
Cygwin DLL.  (Doh!  CVS doing unexpected things strikes again).

Kind regards,

Jon Foster





--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]