|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
problem with SSQLS in header files...Hi,
What are people's thoughts on using SSQLS structures in header files? I'd like to define a class with fetches and processes data from a DB. That class has methods which take and return vectors of rows of the DB, represented by SSQLS structures. The header file for this class I need in other source files so I can use it there. Fine. Trouble is, when is define a struct using sql_create_# in the header file, I get a link error complaining about multiple defintions of symbols <struct name>::names and <struct name>::_table. I can't have the sql_create_# statement in the cpp file of the class (and have a 'struct <struct name>' forward declaration in the header) because then I can't dereference pointers or use iterators to that struct in other cpp files, which is what I want to do. So, what's the solution? Has anyone come across this problem? I'm running os X 10.4, gcc 4, using Eclipse 3.2 and mysql++2.2.1 as an example one of the structs I want (which I define in the namespace dbaccesstypes) is sql_create_7(trade_row, 1, 7, mysqlpp::DateTime, date, float, open, float, high, float, low, float, close, unsigned long, volume, float, adj_close) I then want to do in another source file for example ... vector <dbaccesstypes::trade_row> hist; DateTime from, to; from.convert("2006-11-16 00:00:00"); to.convert("2006-12-01 00:00:00"); dba.gethist(hist, from, to, "IBM"); vector<dbaccesstypes::trade_row>::iterator it; for (it = hist.begin(); it != hist.end(); ++it) { printf("date: %s, open: %d\n", it->date, it->open); } for that I need the full definition of the struct which means putting it in a header file, which leads to the linker errors... "/usr/bin/ld: multiple definitions of symbol dbaccesstypes::instinfo::names ./src/Dbaccess.o definition of dbaccesstypes::instinfo::names in section (__DATA,__data) ./src/dbaccess_test.o definition of dbaccesstypes::instinfo::names in section (__DATA,__data) /usr/bin/ld: multiple definitions of symbol dbaccesstypes::instinfo::_table ./src/Dbaccess.o definition of dbaccesstypes::instinfo::_table in section (__DATA,__data) ./src/dbaccess_test.o definition of dbaccesstypes::instinfo::_table in section (__DATA,__data) /usr/bin/ld: multiple definitions of symbol dbaccesstypes::trade_row::names ./src/Dbaccess.o definition of dbaccesstypes::trade_row::names in section (__DATA,__data) ./src/dbaccess_test.o definition of dbaccesstypes::trade_row::names in section (__DATA,__data) /usr/bin/ld: multiple definitions of symbol dbaccesstypes::trade_row::_table ./src/Dbaccess.o definition of dbaccesstypes::trade_row::_table in section (__DATA,__data) ./src/dbaccess_test.o definition of dbaccesstypes::trade_row::_table in section (__DATA,__data)" suggestions please! thanks, joe -- LIVE MUSIC + OTHER PERFORMANCE ART CHARITY FUNDRAISER Doors 6.30pm - 1st act 7:30pm, 2nd SUNDAY of EVERY month @ THE TALKING HEADS, PORTSWOOD Rd, SOUTHAMPTON £4 entrance: all profits to 3 Local Charities. inc: SCRATCH and HAMPSHIRE AUTISTIC SOCIETY ----------------------------------------------------------------------------------------------- Apr 8th, May 13th... Contact joe.hudson@... for more info. ------------------------------------------------------- --------------------------------------- Visit http://www.myspace.com/littlecog for latest details, to post new events or volunteer for future community action events. |
|
|
RE: problem with SSQLS in header files...I believe the SSQLS macros contain some static variable declarations which causes the linking error when you include the same declaration in two different C files. If you #define MYSQLPP_SSQLS_NO_STATICS before including <custom.h> then that stops the macros adding in instances of the static variables, and will solve the link problem. If you need the functionality provided by the static variables then include each definition once with the statics left enabled (i.e. miss out the #define). See http://lists.mysql.com/plusplus/6204 for more info. Cheers, Matt. -----Original Message----- From: Joe Hudson [mailto:joe.hudson@...] Sent: 18 April 2007 01:32 To: plusplus@... Subject: problem with SSQLS in header files... Hi, What are people's thoughts on using SSQLS structures in header files? I'd like to define a class with fetches and processes data from a DB. That class has methods which take and return vectors of rows of the DB, represented by SSQLS structures. The header file for this class I need in other source files so I can use it there. Fine. Trouble is, when is define a struct using sql_create_# in the header file, I get a link error complaining about multiple defintions of symbols <struct name>::names and <struct name>::_table. I can't have the sql_create_# statement in the cpp file of the class (and have a 'struct <struct name>' forward declaration in the header) because then I can't dereference pointers or use iterators to that struct in other cpp files, which is what I want to do. So, what's the solution? Has anyone come across this problem? I'm running os X 10.4, gcc 4, using Eclipse 3.2 and mysql++2.2.1 as an example one of the structs I want (which I define in the namespace dbaccesstypes) is sql_create_7(trade_row, 1, 7, mysqlpp::DateTime, date, float, open, float, high, float, low, float, close, unsigned long, volume, float, adj_close) I then want to do in another source file for example ... vector <dbaccesstypes::trade_row> hist; DateTime from, to; from.convert("2006-11-16 00:00:00"); to.convert("2006-12-01 00:00:00"); dba.gethist(hist, from, to, "IBM"); vector<dbaccesstypes::trade_row>::iterator it; for (it = hist.begin(); it != hist.end(); ++it) { printf("date: %s, open: %d\n", it->date, it->open); } for that I need the full definition of the struct which means putting it in a header file, which leads to the linker errors... "/usr/bin/ld: multiple definitions of symbol dbaccesstypes::instinfo::names ./src/Dbaccess.o definition of dbaccesstypes::instinfo::names in section (__DATA,__data) ./src/dbaccess_test.o definition of dbaccesstypes::instinfo::names in section (__DATA,__data) /usr/bin/ld: multiple definitions of symbol dbaccesstypes::instinfo::_table ./src/Dbaccess.o definition of dbaccesstypes::instinfo::_table in section (__DATA,__data) ./src/dbaccess_test.o definition of dbaccesstypes::instinfo::_table in section (__DATA,__data) /usr/bin/ld: multiple definitions of symbol dbaccesstypes::trade_row::names ./src/Dbaccess.o definition of dbaccesstypes::trade_row::names in section (__DATA,__data) ./src/dbaccess_test.o definition of dbaccesstypes::trade_row::names in section (__DATA,__data) /usr/bin/ld: multiple definitions of symbol dbaccesstypes::trade_row::_table ./src/Dbaccess.o definition of dbaccesstypes::trade_row::_table in section (__DATA,__data) ./src/dbaccess_test.o definition of dbaccesstypes::trade_row::_table in section (__DATA,__data)" suggestions please! thanks, joe -- LIVE MUSIC + OTHER PERFORMANCE ART CHARITY FUNDRAISER Doors 6.30pm - 1st act 7:30pm, 2nd SUNDAY of EVERY month @ THE TALKING HEADS, PORTSWOOD Rd, SOUTHAMPTON £4 entrance: all profits to 3 Local Charities. inc: SCRATCH and HAMPSHIRE AUTISTIC SOCIETY -------------------------------------------------------------------------- --------------------- Apr 8th, May 13th... Contact joe.hudson@... for more info. ------------------------------------------------------- --------------------------------------- Visit http://www.myspace.com/littlecog for latest details, to post new events or volunteer for future community action events. |
|
|
Re: problem with SSQLS in header files...Matt Dargavel wrote:
> > If you #define MYSQLPP_SSQLS_NO_STATICS before including <custom.h> then > that stops the macros adding in instances of the static variables, and > will solve the link problem. If you need the functionality provided by > the static variables then include each definition once with the statics > left enabled (i.e. miss out the #define). Yes. You can see this technique used in the examples/util module: all of examples/custom*.cpp use the util module, but there is no conflict even though the util module also includes examples/stock.h. -- MySQL++ Mailing List For list archives: http://lists.mysql.com/plusplus To unsubscribe: http://lists.mysql.com/plusplus?unsub=lists@... |
|
|
Re: problem with SSQLS in header files...thanks everyone. problem sorted :)
On 18/04/07, Warren Young <mysqlpp@...> wrote: > > Matt Dargavel wrote: > > > > If you #define MYSQLPP_SSQLS_NO_STATICS before including <custom.h> then > > that stops the macros adding in instances of the static variables, and > > will solve the link problem. If you need the functionality provided by > > the static variables then include each definition once with the statics > > left enabled (i.e. miss out the #define). > > Yes. You can see this technique used in the examples/util module: all > of examples/custom*.cpp use the util module, but there is no conflict > even though the util module also includes examples/stock.h. > > -- > MySQL++ Mailing List > For list archives: http://lists.mysql.com/plusplus > To unsubscribe: > http://lists.mysql.com/plusplus?unsub=joe.hudson@... > > -- LIVE MUSIC + OTHER PERFORMANCE ART CHARITY FUNDRAISER Doors 6.30pm - 1st act 7:30pm, 2nd SUNDAY of EVERY month @ THE TALKING HEADS, PORTSWOOD Rd, SOUTHAMPTON £4 entrance: all profits to 3 Local Charities. inc: SCRATCH and HAMPSHIRE AUTISTIC SOCIETY ----------------------------------------------------------------------------------------------- Apr 8th, May 13th... Contact joe.hudson@... for more info. ------------------------------------------------------- --------------------------------------- Visit http://www.myspace.com/littlecog for latest details, to post new events or volunteer for future community action events. |
|
|
Re: problem with SSQLS in header files...Your header file is fine. In my opinion you're doing nothing wrong - but mysqlpp has a little hoop for you to jump through ! The mysqlpp macro defines two static variables for each struct; 'names' and '_table' When you include the header file, you are including these static definitions - if you include the header file in more than one cpp file, you get the "multiple definitions" error from the linker because it finds one definition of the static variable for each #include. There is a flag in mysqlpp which allows you to include the header file more than once: #define MYSQLPP_SSQLS_NO_STATICS From what I can see of your code, you would put the following into dbaccess.h: #include <mysql++.h> #define MYSQLPP_SSQLS_NO_STATICS #include "trade_row.h" Note also that the static '_table' is what you would use to change the name of the database table accessed by the mysqlpp code. For example, if you want to change the table name to "Trade" but leave the "trade_row" class untouched, you can add this after the includes in your dbaccess.cpp: const char *trade_row::_table = "Trade"; |
| Free embeddable forum powered by Nabble | Forum Help |