gcc does not include extern variables in symbol table when optimisation is used

前端 未结 2 1304
长发绾君心
长发绾君心 2021-01-27 18:30

My program contains many externally defined variables. When I compile it with -O0 flag, I see them in the symbol table, but not when I use -O1 or -O2. How can I force the compil

2条回答
  •  隐瞒了意图╮
    2021-01-27 18:49

    With `-O1' and '-O2', the compiler tries to reduce code size and execution time. One of the optimizations used to reduce the size of the resulting executable is to 'throw everything overboard' that is not required for execution. The symbol table of an executable is one of those debugging niceties that is really not required for execution; so it is excluded from the final output file.

    ('-O0' means "Do no optimizations").

提交回复
热议问题