public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: Exporting const variables from DLLs (GCC bug?)
@ 2003-11-16 21:30 Danny Smith
  0 siblings, 0 replies; 2+ messages in thread
From: Danny Smith @ 2003-11-16 21:30 UTC (permalink / raw)
  To: cygwin

Jon Foster wrote:

> 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
>


It is a bug in gcc.  The above code compiles okay with C, but
strangely, not C++.  For some reason, g++ does not immediately
mark the the definition of global constants as public when they
are defined after a prior declaration.  I have a fix that I will
submit to gcc-patches after reg-testing

Danny

http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.

--
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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Exporting const variables from DLLs (GCC bug?)
@ 2003-11-16 18:59 Jon Foster
  0 siblings, 0 replies; 2+ messages in thread
From: Jon Foster @ 2003-11-16 18:59 UTC (permalink / raw)
  To: cygwin

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-11-16 21:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-16 21:30 Exporting const variables from DLLs (GCC bug?) Danny Smith
  -- strict thread matches above, loose matches on Subject: below --
2003-11-16 18:59 Jon Foster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).