[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 06:56:14 PDT 2021


On 20/09/2021 12:36, John Emmas via cfe-users wrote:
>
> 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 is there maybe some linker option that'll tell 
> Clang to ignore variables if the code never needs access to them?
>

Another possibility just occurred to me...  here's a real-world example 
from our code:-

#if defined (BUILDING_DLL)
   #define DLL_API __declspec(dllexport)
#else
   #define DLL_API __declspec(dllimport)
#endif

namespace Gtkmm2ext {

   class DLL_API Keyboard
   {
     public:
       Keyboard ();
       ~Keyboard ();

       static Keyboard& the_keyboard() { return *_the_keyboard };

     protected:
       static Keyboard* _the_keyboard;
   };

} /* namespace */

The above example is from a DLL but when I try to build the 
corresponding EXE, Clang's linker complains that it can't find 
'_the_keyboard' - so did the compiler (maybe) implement its call to 
'the_keyboard()' as inline code, rather than importing it from the DLL?  
Maybe for very simple code like this, Clang will try to be clever and 
implement stuff inline if it can?  And if so, is there some way to turn 
off that feature?  Thanks,

John


More information about the cfe-users mailing list