Bug 29085 - Turning on precompiled header with anonymous namespaces spoils linking.
Summary: Turning on precompiled header with anonymous namespaces spoils linking.
Status: RESOLVED DUPLICATE of bug 10591
Alias: None
Product: gcc
Classification: Unclassified
Component: pch (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-14 15:57 UTC by _Vi
Modified: 2021-11-05 23:18 UTC (History)
19 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _Vi 2006-09-14 15:57:29 UTC
### How to create bug situation.
vi@vi:~/code/test$ ls
q.c  stable.h  w.c

vi@vi:~/code/test$ cat stable.h
namespace {
  int qwerty;
}

vi@vi:~/code/test$ cat q.c
#include "stable.h"
int main(){return 0;}

vi@vi:~/code/test$ cat w.c
#include "stable.h"

### Try to compile them
vi@vi:~/code/test$ g++ -c q.c && g++ -c w.c && g++ q.o w.o
vi@vi:~/code/test$ # Everything is allright.

### Now try to use precompiled headers
vi@vi:~/code/test$ g++ -x c++-header stable.h
vi@vi:~/code/test$ g++ -c q.c && g++ -c w.c && g++ q.o w.o
w.o:(.bss+0x0): multiple definition of `(anonymous namespace)::qwerty'
q.o:(.bss+0x0): first defined here
collect2: ld returned 1 exit status
vi@vi:~/code/test$ # It changes behavior!

### Verbose
vi@vi:~/code/test$ g++ --version
g++ (GCC) 4.1.1
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

vi@vi:~/code/test$ g++ -x c++-header -v stable.h 2>&1 | less
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.1.1/configure --with-languages=c,c++,java
Thread model: posix
gcc version 4.1.1
 /usr/local/libexec/gcc/i686-pc-linux-gnu/4.1.1/cc1plus -quiet -v -D_GNU_SOURCE
stable.h -quiet -dumpbase stable.h -mtune=pentiumpro -auxbase stable -version -o
 /tmp/ccJclyGu.s --output-pch=stable.h.gch
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../..
/../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/qt/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../include/c++/4.1.1
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../include/c++/4.1.1/i686-p
c-linux-gnu
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../include/c++/4.1.1/backwa
rd
 /usr/local/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/include
 /usr/include
End of search list.
GNU C++ version 4.1.1 (i686-pc-linux-gnu)
        compiled by GNU C version 4.1.1.
GGC heuristics: --param ggc-min-expand=38 --param ggc-min-heapsize=15796
Compiler executable checksum: 0df7441bd54adeeb14f3ed5c0d3ee62c

g++ q.c w.c -v 2>&1 | less
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.1.1/configure --with-languages=c,c++,java
Thread model: posix
gcc version 4.1.1
 /usr/local/libexec/gcc/i686-pc-linux-gnu/4.1.1/cc1plus -quiet -v -D_GNU_SOURCE
q.c -quiet -dumpbase q.c -mtune=pentiumpro -auxbase q -version -o /tmp/cc5SON1S.
s
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../..
/../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/qt/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../include/c++/4.1.1
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../include/c++/4.1.1/i686-p
c-linux-gnu
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../include/c++/4.1.1/backwa
rd
 /usr/local/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/include
 /usr/include
End of search list.
GNU C++ version 4.1.1 (i686-pc-linux-gnu)
        compiled by GNU C version 4.1.1.
GGC heuristics: --param ggc-min-expand=38 --param ggc-min-heapsize=15796
Compiler executable checksum: 0df7441bd54adeeb14f3ed5c0d3ee62c
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/bin/as
 -V -Qy -o /tmp/ccwwqFsN.o /tmp/cc5SON1S.s
GNU assembler version 2.17 (i686-pc-linux-gnu) using BFD version 2.17
 /usr/local/libexec/gcc/i686-pc-linux-gnu/4.1.1/cc1plus -quiet -v -D_GNU_SOURCE
w.c -quiet -dumpbase w.c -mtune=pentiumpro -auxbase w -version -o /tmp/cc5SON1S.
s
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../..
/../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/qt/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../include/c++/4.1.1
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../include/c++/4.1.1/i686-p
c-linux-gnu
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../include/c++/4.1.1/backwa
rd
 /usr/local/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/include
 /usr/include
End of search list.
GNU C++ version 4.1.1 (i686-pc-linux-gnu)
        compiled by GNU C version 4.1.1.
GGC heuristics: --param ggc-min-expand=38 --param ggc-min-heapsize=15796
Compiler executable checksum: 0df7441bd54adeeb14f3ed5c0d3ee62c
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/bin/as
 -V -Qy -o /tmp/ccO6zFNO.o /tmp/cc5SON1S.s
GNU assembler version 2.17 (i686-pc-linux-gnu) using BFD version 2.17
 /usr/local/libexec/gcc/i686-pc-linux-gnu/4.1.1/collect2 --eh-frame-hdr -m elf_i
386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/loca
l/lib/gcc/i686-pc-linux-gnu/4.1.1/crtbegin.o -L/usr/local/lib/gcc/i686-pc-linux-
gnu/4.1.1 -L/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux
-gnu/lib -L/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/../../.. /tmp/ccwwqFsN.o /
tmp/ccO6zFNO.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/lib/gcc/i
686-pc-linux-gnu/4.1.1/crtend.o /usr/lib/crtn.o
/tmp/ccO6zFNO.o:(.bss+0x0): multiple definition of `(anonymous namespace)::qwert
y'
/tmp/ccwwqFsN.o:(.bss+0x0): first defined here
collect2: ld returned 1 exit status

### Such structures are in use in boost/lambda/core.hpp header, and multi-unit project ceases to link if precompiled headers are enabled (otherwise it works).
Comment 1 Andrew Pinski 2006-09-14 16:01:48 UTC
This is a dup of bug 10591 which will be fixed with the release of 4.2.0.

*** This bug has been marked as a duplicate of 10591 ***
Comment 2 Tim Turner 2021-11-05 23:18:25 UTC Comment hidden (spam)