astromatic/sextractor

Failling to build with incoming gcc10 (-fno-common default)

Opened this issue · 7 comments

gcc 10 (not released yet) has changed the management of global variables: they say that they were ignoring a common C error. Now the flag -fno-common is set to default

https://gcc.gnu.org/gcc-10/porting_to.html

If you compile with gcc 10 or an older gcc with -fno-common, like this:

$ CFLAGS="-fno-common" ./configure
$ make

you get a lot of linking errors like this:

/usr/bin/ld: winpos.o:(.bss+0x40e0): multiple definition of `prefs'; analyse.o:(.bss+0x40e0): first defined here
/usr/bin/ld: xml.o:(.bss+0x0): multiple definition of `bswapflag'; analyse.o:(.bss+0x0): first defined here

As I understand the problem, as bswapflag appears in fitscat.h as

int		bswapflag

and fitscat.h is included by other C files, the variable is defined multiple times. Now the compiler refuses to do that.

The fix should be to define bswapflag only in one C files and keep the declarations in header files with extern

Thanks! Fixed in 46dd48f. Could you please check that it works now in gcc10? Thanks again.

Sorry I haven't checked before, but the fix doesn't work. I still get the same errors after pulling from git. The error is related with extern variables, but you haven't modified any in your commit

OK thanks. I should have tried myself. Well there is no bswapflag variable anymore . There is actually a huge number of changes I have to make. This will have to wait a few weeks I am afraid.

Thank you. This same problem appears in other programs such as psfex and swarp. Some of the offending variables appear in the same places (in the libfits library) so a fix hopefully will work for all the programs

OK. Just need to find the time as usual.

The patches to avoid multiple definitions of the symbols (caused by using declarations in multiply included header files) have been assembled - at least for sextractor - in the sextractor.patch in https://build.opensuse.org/package/show/home:rjmathar/sextractor .
Basically the definitions in the header files are declared extern and only the main programs define one instance of the variables needed.

The -fno-common flag is set by default in GCC 10.3.0 supplied with Ubuntu 20.10. The workaround is, naturally

./configure CFLAGS="-fcommon"

but it requires googling this GitHub Issue to realize what's going on.