DrylandEcology / STEPWAT2

folder
4 stars 5 forks source link

Compilation fails with gcc >= v10 due to duplicate symbols #512

Closed dschlaep closed 2 years ago

dschlaep commented 2 years ago

STEPWAT2 fails to compile with gcc versions 10 and later:

gcc starting with v10 changed the default from -fcommon to -fno-common, e.g., https://gcc.gnu.org/gcc-10/porting_to.html

STEPWAT2 defines several global variables in header files; the header files themselves are not protected against multiple includes; thus, these variables are defined multiple times (each time the header file is included):

duplicate symbol _mortality_rng in: obj/ST_environs.o obj/ST_grid.o duplicate symbol _UseCheatgrassWildfire in: obj/ST_environs.o obj/ST_grid.o ...

Suggested solution: define these variables in code (instead of header) and declare as externed in header if needed

Also consider protecting header files from being included multiple times.

Quick fix until this issue is properly resolved: compile with option -fcommon