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

Jeffrey Walton via cfe-users cfe-users at lists.llvm.org
Mon Sep 20 13:14:37 PDT 2021


On Mon, Sep 20, 2021 at 7:37 AM John Emmas via cfe-users
<cfe-users at lists.llvm.org> wrote:
>
> 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;
>
> ...
> 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...

'revision_num' is declared static. Try 'extern static int revision_num'.

Getting this sort of thing to compile under different compilers can be
tricky. Especially when exporting templates.

Jeff


More information about the cfe-users mailing list