[LAD] G++ trouble
Will J Godfrey
WillGodfrey at musically.me.uk
Mon Nov 16 14:38:01 CET 2020
On Mon, 16 Nov 2020 13:35:30 +0100
Fons Adriaensen <fons at linuxaudio.org> wrote:
>On Mon, Nov 16, 2020 at 12:22:54PM +0000, Will J Godfrey wrote:
>> In GCC 8.3 doing that in a globally included header actually *creates* a
>> multiple definitions error!
>> #ifndef GLOBALS_H
>> #define GLOBALS_H
>> const unsigned int ADD_COLOUR = 0xdfafbf00; fine
>Putting a definition in a header file is usually a bad idea.
>What you get from this (without 'extern' is a separate copy
>in each file that includes the header. GCC 8 will not flag
>this as an error.
>> extern const unsigned int ADD_COLOUR = 0xdfafbf00; boom!
>This normally should not create ADD_COLOUR, just tell the
>compiler that it exists somewhere. So this should result
>in an 'undefined' error.
>If OTOH you get a 'multiple definition' error that would
>normally mean there are other definitions as well. Maybe
>you had this in a number of files, decided later to make
>it a single global, and forgot to delete the originals ?
Not wishing to hijack this thread but I'm still confused :(
I just did a search of the whole of src. It's *used* about a dozen times
across 5 otherwise unrelated .cpp files, but is only defined here. Just to be
certain, I did a make clean before trying this again, and it's definitely saying
multiple definition of `ADD_COLOUR';
This happens at the linker stage.
Also, I thought the whole idea of putting things like this in a #ifndef/#def
block was to ensure it was only set once.
It wasn't me! (Well actually, it probably was)
... the hard part is not dodging what life throws at you,
but trying to catch the good bits.
More information about the Linux-audio-dev