Ceedling icon indicating copy to clipboard operation
Ceedling copied to clipboard

Multiply defined variables when using gcc v10.2.0

Open abergerSRS opened this issue 5 years ago • 4 comments

gcc fails to compile test code, throwing "multiple definition of" errors when using gcc v10.2.0. Issue is not present with gcc v8.1.0

abergerSRS avatar Dec 03 '20 22:12 abergerSRS

Same here. I attach a test project

Globals.zip

This is the output with GCC 5

image

And this is the output with GCC 10

image

mundodisco8 avatar Dec 07 '20 10:12 mundodisco8

Please check this link about porting to GCC 10. Now -fno-common flag is used by default what cause problems.

I think you can add this section to your project.yml file to achieve behavior like for previous GCC version:

:flags:
  :test:
    :compile:
      :*:
        - -fcommon

CezaryGapinski avatar Dec 07 '20 15:12 CezaryGapinski

Would it be a more 'proper' solution to change the code with extern variables or modify the project.yml with "f-common" flag? Thanks!

groundstack avatar May 03 '21 14:05 groundstack

The C standards require that variables be defined only once, e.g. int x;, and be declared with extern int x; in all other files. In particular, a header file should almost always have extern declarations. -fcommon is basically a workaround for old programs that don't conform.

johnwcowan avatar Sep 26 '22 14:09 johnwcowan