There seems to be a bug in the name mangling of a function inside a unnamed namespace (using g++ 4.1.0), when the compilation unit uses a precompiled header which contains another unnamed namespace. This is better demonstrated with the following setup:
pch.h: namespace { void inside_pch(){} } test1.cpp: #include "pch.h" namespace { void test(){} } int main() {} test2.cpp: #include "pch.h" namespace { void test(){} } Showing the bug: g++ pch.h g++ -o test1.o -c test1.cpp g++ -o test2.o -c test2.cpp g++ -o test test1.o test2.o test2.o: In function `(anonymous namespace)::inside_pch()': test2.cpp:(.text+0x0): multiple definition of `(anonymous namespace)::inside_pch()' test1.o:test1.cpp:(.text+0x0): first defined here test2.o: In function `(anonymous namespace)::test()': test2.cpp:(.text+0x6): multiple definition of `(anonymous namespace)::test()' test1.o:test1.cpp:(.text+0x6): first defined here collect2: ld returned 1 exit status nm test1.o shows: U __gxx_personality_v0 0000000c T main 00000000 T _ZN34_GLOBAL__N_pch.h_00000000_ECAA0BAE10inside_pchEv 00000006 T _ZN34_GLOBAL__N_pch.h_00000000_ECAA0BAE4testEv nm test2.o shows: U __gxx_personality_v0 00000000 T _ZN34_GLOBAL__N_pch.h_00000000_ECAA0BAE10inside_pchEv 00000006 T _ZN34_GLOBAL__N_pch.h_00000000_ECAA0BAE4testEv While the incorrect mangling of unnamed namespace inside a pch is a longstanding bug, function test, both in test1.cpp and test2.cpp used to be mangled correctly, at least with g++ 3.4.5. Doing the same with g++ 3.4.5, we have as result the following error message: test2.o: In function `(anonymous namespace)::inside_pch()': test2.cpp:(.text+0x0): multiple definition of `(anonymous namespace)::inside_pch()' test1.o:test1.cpp:(.text+0x0): first defined here collect2: ld returned 1 exit status This time, nm test1.o returns: 0000000c T main 00000000 T _ZN34_GLOBAL__N_pch.h_00000000_7F4453F410inside_pchEv 00000006 T _ZN38_GLOBAL__N_test1.cpp_00000000_6EC548D94testEv and nm test2.o 00000000 T _ZN34_GLOBAL__N_pch.h_00000000_7F4453F410inside_pchEv 00000006 T _ZN38_GLOBAL__N_test2.cpp_00000000_D5E9623F4testEv: I hope this information helps. -- Summary: Bug mangling function name inside unnamed namespace, with pch Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: pch AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rodolfo at rodsoft dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26895