Making a forward declaration of a C symbol defined in another CU

Alexander Nicholi alex at
Thu Dec 20 08:17:58 UTC 2018

I'm developing for Windows, 64-bit at the moment with MSVC and 
DMD. I have this C code file, config.c:

     #define STRINGIZE( x ) STRINGIZE_( x )
     #define STRINGIZE_( x ) #x

     const xu16 ocoCoreVerMajor   = _MILES_VER_MAJOR;
     const xu16 ocoCoreVerMinor   = _MILES_VER_MINOR;
     const xu16 ocoCoreVerPatch   = _MILES_VER_PATCH;
     const char* ocoCoreVerBuild  = STRINGIZE( _MILES_VER_BUILD );
     const char* ocoCoreTimestamp = STRINGIZE( _MILES_BUILD_TSTAMP 

And for D code, I have this interface, config.d:

     module oco.core.config;

     extern (C) const ushort ocoCoreVerMajor;
     extern (C) const ushort ocoCoreVerMinor;
     extern (C) const ushort ocoCoreVerPatch;
     extern (C) const char* ocoCoreVerBuild;
     extern (C) const char* ocoCoreTimestamp;

The linker gives me this error:

     [ÔÇô/debug] Linking         oco...
     [ÔÇô/debug stop] config.d.obj : error LNK2005: 
ocoCoreVerMajor already defined in
     [ÔÇô/debug stop] 
C:\Users\Alex\AppData\Local\Temp\miles-build\oco.exe : fatal 
error LNK1169: one or more multiply defined symbols found
     [ÔÇô/debug stop]

I figure the D code is defining symbols redundantly, and they're 
not weakly defined, so this happens. Obviously I can't exactly 
just hand the definitions into D, as you can see by the C code 
this is actually the best way to pass these values around across 
language boundaries (there are a few). How do I tell D to treat 
this right?

More information about the Digitalmars-d mailing list