https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93703
Bug ID: 93703 Summary: global const getting lost in g++ Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: felix-gcc at fefe dot de Target Milestone: --- I suspect this is my mistake, not gcc's, but I'm out of ideas so sorry for wasting your time if that is true. Here is my situation: $ cat a.cc const int foo = 23; $ cat b.cc extern const int foo; int main() { return foo; } $ g++ -o x a.cc b.cc /usr/lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccXS1J5J.o: in function `main': b.cc:(.text+0x6): undefined reference to `foo' collect2: error: ld returned 1 exit status $ Wait, what? $ g++ -c a.cc b.cc && nm a.o b.o a.o: 0000000000000000 r _ZL3foo b.o: U foo 0000000000000000 T main $ What the...? Why is foo mangled in a.o but not in b.o? I tried this with clang++ too and there it's even worse: a.o is empty and does not even export a mangled foo. What am I missing?