[cfe-users] Clang (with Visual Studio) wrongly complains about missing variables

John Emmas via cfe-users cfe-users at lists.llvm.org
Mon Sep 20 04:36:56 PDT 2021


Hi there - I'm building quite a complex Windows program here using 
VS2019.  Obviously there's an EXE and there's maybe 30 or so DLLs. Some 
DLL's might have code which looks like this in a header file:-

     class whatever {
         static int revision_num;
     };

or if there's no class involved it'd maybe look like this:-

     extern int revision_num;

The actual int would then be instantiated in one of the DLL's source 
files.  IIUC it's done like this to ensure that there's only ever one 
copy of 'revision_num'.  It's internal to the DLL and typically, the DLL 
will offer an exported function called 'get_revision_num()' so that code 
in other modules (e.g. in the exe) can access it.  This all builds fine 
if I use VS2019's MSVC compiler.

But if I switch VS2019 to use Clang (when building the EXE) Clang's 
linker will complain that it can't find the variable 'revision_num'.  
But of course, 'revision_num' is an internal variable that's private to 
the DLL - so the EXE should never need to know about it.  Is this a 
known issue when using Clang with Visual Studio?  Or is there maybe some 
linker option that'll tell Clang to ignore variables if the code never 
needs access to them?  Hope that makes sense...

John


More information about the cfe-users mailing list