I have a big piece of code that creates compilation errors using -flto
only on some versions of gcc. I will try to summarize below
in file1.h
extern char A [100];
in file1.c
#include "file1.h" char A[100];
I also have C ++ code that uses the variable A
C ++ code is compiled into an .o
file, and then it all compiled with something like
gcc file1.c cpp.o
Using the gcc version on archlinux (5.2.0), there is no problem with or without -flto
. However, using gcc on Ubuntu 14.04 (4.8.4), when the code is compiled with -flto
, A
becomes a local variable. I checked this with nm:
This is the output from nm a.out
for the variable in question.
Ubuntu, no lto (similar arch, with a different number):
00000000006162e0 BA
Ubuntu lto
00000000006092c0 b A.2722
I understand that B
is for a global variable, but B
is not.
How can I guarantee that A
supported as a global variable, even when I use -flto
in Ubuntu?
source share