32

I found that my project sets

GCC_NO_COMMON_BLOCKS = NO 

under Apple LLVM Compiler 3.1 - Code Generation settings, as "No Common Blocks"

enter image description here

I would like to know: what is that flag used for?

Thanks a lot

Lio
  • 4,225
  • 4
  • 33
  • 40

1 Answers1

49

From Xcode's quick help:

In C, allocate even uninitialized global variables in the data section of the object file, rather than generating them as common blocks. This has the effect that if the same variable is declared (without extern ) in two different compilations, you will get an error when you link them. The only reason this might be useful is if you wish to verify that the program will work on other systems which always work this way.

You can find the quick help in the right pane, under the "Show Quick Help Inspector" tab: Xcode Quick Help Inspector

Paul R
  • 208,748
  • 37
  • 389
  • 560
JustSid
  • 25,168
  • 7
  • 79
  • 97
  • 5
    Thanks! I didn't know that XCode's quick help also helped with build settings and that stuff. That would have saved me some time. – Lio Jun 27 '12 at 19:12
  • 5
    This option seems to be turned on by Xcode 8 recommended settings. – Richard Sep 24 '16 at 18:59
  • 5
    the problem of it being on by default in Xcode 8 is it will mess a whole bunch of existing projects up by probably a vast majority of developers over many years.. and the "error" generated in most cases (if not all) will not point to which variables are "common", nor does the error give a hint that it is even related to "common" variables, nor is there any hint that the error's root was an (automatic) compiler setting change that caused the difference. – hokkuk Apr 18 '17 at 22:13
  • 1
    This setting was turned on by Xcode 9 recommended settings and broke my build! – Chuck Krutsinger Sep 26 '17 at 22:39
  • 2
    I read the quick help and still don't know why I would want to do this or not. Xcode 9 changed this setting on one of my projects and broke the build. I was able to modify my code so that I could retain the YES setting for common blocks, but I still don't know why this is recommended and what its benefit might be. – Chuck Krutsinger Sep 26 '17 at 23:07
  • Saved me. I've spend ~1.5 days struggling with linker errors. – surfrider Dec 03 '19 at 13:23
  • 1
    But what does this do? – user16217248 Jun 26 '21 at 00:51
  • From GCC docs: "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". As I understand, one should set this to `YES` by default in order to avoid unexpected behaviour when accidentally defined the same variable in 2+ modules. Meanwhile, you might have to set it to `NO` for backwards compatibility with code you don't own. – Legonaftik Mar 02 '22 at 03:26