List:MySQL++« Previous MessageNext Message »
From:Wolfram Arnold Date:July 6 2005 8:15am
Subject:static globals in SSQL macro expansion -> multiple definition
linker errors
View as plain text  
Hi,

While we're talking about wish-lists for version 2.0, I have an item to
contribute.  In fact, it surprised me this hasn't been addressed yet, or
maybe I'm missing something.

The SSQL macro expansion will create static globals that are being
defined (assinged) as part of the macro.  With the ssqls-pretty tool it
was easy to see that...

sql_create_7(PriceData,
	     6,
	     7,
	     Date, date,
	     int, open,
	     int, high,
	     int, low,
	     int, close,
	     int, volume,
	     int, suspended);

...expands into...


struct PriceData {
[...]
  static const char *names[];
  static const char *_table;
[...]
};

[...]

const char *PriceData::names[] = {
"date" , "open" , "high" , "low" , "close" , "volume" , "suspended" };

[...]

This is fine and dandy, as long as the SSQL macro expansion is used in
only one .cpp source file in the application.  If the SSQL macro is put
into a header file and include it into multiple .cpp source files, then
the linker will invariably complain that names and _tables are multiply
defined symbols.

I've only tried this with version 1.7.35 so far, but I haven't seen
anything in the release notes since that this behavior has been changed.

Can this be fixed?  Not being able to share SSQL structures across
compilation units inhibits code modularity in cases where the Database
table is the common data structure shared between many different clients
in an application.

Could the macro be split into two or take an extra flag to optionally
not generate the definition for the globals?  I'd be glad to give this a
shot, but I wanted to hear from the community if there is any reason
other than lack of volunteers.  This has come up before; I found mailing
list articles as far back as 2001 on this.

Cheers,

Wolfram


-- 
Wolfram Arnold <wolfram@stripped>


Thread
static globals in SSQL macro expansion -> multiple definitionlinker errorsWolfram Arnold6 Jul
  • Re: static globals in SSQL macro expansion -> multiple definition linker errorsChris Frey6 Jul
    • Re: static globals in SSQL macro expansion -> multiple definitionlinker errorsWolfram Arnold6 Jul
    • Re: static globals in SSQL macro expansion -> multiple definitionlinker errorsWarren Young6 Jul
      • Re: static globals in SSQL macro expansion -> multiple definition linker errorsChris Frey6 Jul
        • Re: static globals in SSQL macro expansion -> multiple definitionlinker errorsWarren Young6 Jul
          • Re: static globals in SSQL macro expansion -> multiple definition linker errorsChris Frey7 Jul
            • Re: static globals in SSQL macro expansion -> multiple definitionlinker errorsWarren Young7 Jul
              • Re: static globals in SSQL macro expansion -> multiple definition linker errorsChris Frey8 Jul
                • Re: static globals in SSQL macro expansion -> multiple definitionlinker errorsWarren Young8 Jul
              • Unresolved External SymbolBrian Farmer14 Jul
                • Re: Unresolved External SymbolWarren Young14 Jul
                • Connection always on and field namesAnkur G35 Saxena17 Jul
                  • Re: Connection always on and field namesWarren Young18 Jul
  • Re: static globals in SSQL macro expansion -> multiple definitionlinker errorsWarren Young6 Jul