On Sun, Jun 12, 2016 at 11:48 AM, John Ralls <jra...@ceridwen.us> wrote: > > > > > > > I'm not using guid's in my code. These errors are pulled in because of > the Account.h header > > that gets included somewhere. > > > > I saw one commit on the guid_header branch is including guid.hpp > everywhere. Is that what I > > now have to do in my sources even if I'm not using a guid directly ? Or > what is the correct > > approach here ? > > > > Yes, I had a similar problem in the backend work after I merged, though > the backend code obviously does use GncGUID so it didn't seem quite as > weird. Try including guid.hpp before gnc-csv-account-map.h in > gnc-csv-imp-trans.cpp. > > It might work to conditionally include guid.hpp inside of guid.h and wrap > guid.hpp's declarations in extern "C" > to avoid linkage problems. If so that would allow us to remove all of the > sxplicit include guid.hpp from .cpp files. > > Aaron, any thoughts on this? > > Regards, > John Ralls
tl;dr: This can be made better by making a small change in guid.h which I will Pull Request within the next day or so. With this change, any .cpp file that doesn't need the definition of GncGUID doesn't have to include guid.hpp at the top. Long version: The problem here is that there is one definition of GncGUID for C code and one for C++ code (this is in the commit message). I was unable to do something like #ifdef __cplusplus struct GncGUID : public boost::uuids::uuid... #else typedef struct _gncGuid { unsigned char..... #endif because rather than trusting C headers to use extern "C" when they need it, we use extern "C" around C headers "for" them. This means that, even when compiling c++, the linkage could be "C". For example: kvp-value.cpp includes kvp-value.hpp which uses extern "C" to include qof.h which includes guid.h. Although a c++ compiler is being invoked, the linkage is "C", so a c++ definition can't be conditionally included here. For the same reason, we can't #ifdef __cplusplus #include "guid.hpp" #endif etc. Also, GncGUID must be defined before it's used! This means that the best place to put it is first in a .cpp file (perhaps after config.h is more correct), and of course, not within an extern "C" block. The solution I have is that I can simply forward declare the struct in the #ifdef __cplusplus. I can't put the definition in there because of the "C" linkage problem, but I forgot that I *can* forward declare, and that's what I plan to do. I just did a test run in libqof, and it allowed me to remove a guid.hpp include is almost 20 files. Thanks for bringing this to my attention; please let me know if you have any more thoughts! _______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel