fix multiple definitions of CDT variables under MinGW on Windows
Building with MinGW on Windows resulted in lots of build errors of the form:
…/x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\cdt.dir/objects.a(dtdisc.c.obj):
dtdisc.c:(.bss+0x0): multiple definition of `Dtset';
CMakeFiles\cdt.dir/objects.a(dtclose.c.obj):dtclose.c:(.bss+0x0): first
defined here
The problem is that this environment defines _WIN32, so it sees the __declspec
alternatives for CDT_API in cdt.h. This is fine as GCC understands __declspec,
but it results in variable declarations in this header then missing the extern
qualifier. GCC’s semantics, in contrast to MSVC, interpret this as a definition
rather than a declaration.
The solution here is to *always* apply extern to these declarations, as MSVC is
happy with this as well. This is only addressing the immediate cause, and not
the longer term issue that __declspec(dllexport) and __declspec(dllimport) in a
Windows build should really be mapped to __attribute__((visibility("default")))
and __attribute__((visibility("hidden"))) in a non-Windows build, not to extern.
Thanks to @Synoecium and @swaldhoer for guidance on this fix.