Ubuntu 22.04.1 : GCC 11 ( -fcommon ) : Issue … Multiple definition of.

Avec GCC 11 on a changer la valeur par défaut.

Donc pour supprimer les problèmes (de facon rapide) il suffit d’ajouter la directive -fcommon. La solution idéale est de revoir le code … et surtout les .h.

Misère.

Pour information Ubuntu 22.04.1 utilise gcc 11.2.0-19 .

La doc : https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html

-fcommon

In C code, this option controls the placement of global variables defined without an initializer, known as tentative definitions in the C standard. Tentative definitions are distinct from declarations of a variable with the extern keyword, which do not allocate storage.

The default is -fno-common, which specifies that the compiler places uninitialized global variables in the BSS section of the object file. This inhibits the merging of tentative definitions by the linker so you get a multiple-definition error if the same variable is accidentally defined in more than one compilation unit.

The -fcommon places uninitialized global variables in a common block. This allows the linker to resolve all tentative definitions of the same variable in different compilation units to the same object, or to a non-tentative definition. This behavior is inconsistent with C++, and on many targets implies a speed and code size penalty on global variable references. It is mainly useful to enable legacy code to link without errors.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Time limit is exhausted. Please reload CAPTCHA.