Reputation: 246
I'm using mysql++ (Tangentsoft) for years now (in C++) and due to some mass inserts, I'm trying to switch to their suggested way for using their (!!!) command size controlled way to do massinserts: an insert function that takes iterators as data input.
My problem is, that the (moster) macros sql_create_# besides tons of other things create two static class members (named "names" and "table") that are no declarations but already implementations. This works as long as the generated structures are only used form ONE source code file (e.g. a *.cpp). But as soon as I need the generated structures in header files, they are #include'ed several times and the mentioned two instantiations will complain when linking about being instantiated multiple times ... fully correct.
Is there some way to change the behavior of mysqlpp's macros "sql_create_#" to NOT instantiate anything but only declare the required structures?
The only way that comes to my mind is to fetch the sql_create_# macros's expansion and modify that code manually to be fit for usage multiple times (e.g. in my header files).
following are the two generated snippets (out of a macro expansion of ~540 lines for a 4-column-table) that cause the trouble (including the ugly indentation :-/) that should IMHO be declared as external and instatiated by separate macros.
int compare (const gridData &other) const \
{return sql_compare_gridData<mysqlpp::sql_dummy>(*this,other);} static const char* names[];\
...
static void table(const char* t) { table_ = t; }\
private:\
static const char* table_;\
const char* table_override_;\
};\
Do I somehow missuse these macros in some way or is this a bug in the mysql++ framework? (Comment: ALL the examples indeed ARE one-file-examples where this limitation does not hurt)
Upvotes: 0
Views: 19
Reputation: 246
the linker flag --allow-multiple-definition
will do the trick, ignoring duplicate symbols, just using the first one. It should be guaranteed, that indeed ALL duplicates are the SAME implementation and do not differ (e.g. in versioning or else)
Upvotes: 0