Skip to content

Commit df87984

Browse files
authored
[ML] Fix the debug build on Windows (#430)
rapidjson::Writer<rapidjson::StringBuffer> is exported from the core library (implicitly rather than explicitly, because CRapidJsonConcurrentLineWriter inherits from it and is exported). To avoid violating the one-definition rule, other libraries that link to the core library (i.e. all of them) and use rapidjson::Writer<rapidjson::StringBuffer> must import the instantiation in the core library rather than reinstantiating the template themselves. This change is basically working around item 2 in http://developercommunity.visualstudio.com/solutions/228892/view.html It's only strictly necessary to do this at the moment when building with debug as in an optimised build the clashing methods get inlined, so don't generate clashing symbols. However, future code changes could cause the compiler to inline different methods, so it's best to always import the instantiation exported from the core library.
1 parent fce675b commit df87984

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/api/CDataFrameAnalysisConfigReader.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@
1414

1515
#include <cstring>
1616

17+
#ifdef Windows
18+
// rapidjson::Writer<rapidjson::StringBuffer> gets instantiated in the core
19+
// library, and on Windows it gets exported too, because
20+
// CRapidJsonConcurrentLineWriter inherits from it and is also exported.
21+
// To avoid breaching the one-definition rule we must reuse this exported
22+
// instantiation, as deduplication of template instantiations doesn't work
23+
// across DLLs. To make this even more confusing, this is only strictly
24+
// necessary when building without optimisation, because with optimisation
25+
// enabled the instantiation in this library gets inlined to the extent that
26+
// there are no clashing symbols.
27+
template class CORE_EXPORT rapidjson::Writer<rapidjson::StringBuffer>;
28+
#endif
29+
1730
namespace ml {
1831
namespace api {
1932
namespace {

0 commit comments

Comments
 (0)