[LAD] G++ trouble
k.s.matheussen at gmail.com
Mon Nov 16 13:10:55 CET 2020
On Mon, Nov 16, 2020 at 12:59 PM Roman Sommer <roman.sommer at fau.de> wrote:
> Kjetil Matheussen <k.s.matheussen at gmail.com> writes:
> > Yeah, I just read this: https://gcc.gnu.org/gcc-10/porting_to.html
> > "
> > C language issues
> > Default to -fno-common
> > A common mistake in C is omitting extern when declaring a global
> > variable in a header file. If the header is included by several files
> > it results in multiple definitions of the same variable. In previous
> > GCC versions this error is ignored. GCC 10 defaults to -fno-common,
> > which means a linker error will now be reported. To fix this, use
> > extern in header files when declaring global variables, and ensure
> > each global is defined in exactly one C file. If tentative definitions
> > of particular variables need to be placed in a common block,
> > __attribute__((__common__)) can be used to force that behavior even in
> > code compiled without -fcommon. As a workaround, legacy C code where
> > all tentative definitions should be placed into a common block can be
> > compiled with -fcommon.
> > int x; // tentative definition - avoid in header files
> > extern int y; // correct declaration in a header file
> > "
> > Guess that could explain it.
> Hm? Why would that explain this behaviour?
> It seems to me Fons already (correctly) uses "extern" in his header
Guess you're right. I didn't read the posts very thoroughly. That's
also why I wrote "could' and not "would".
More information about the Linux-audio-dev