Bug 10707 - c++ linking impossible when -V specified
Summary: c++ linking impossible when -V specified
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 3.4.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 11143 13036 14825 15940 17375 19504 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-05-09 16:06 UTC by gawrilow
Modified: 2010-05-22 17:55 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-31 20:29:43


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gawrilow 2003-05-09 16:06:00 UTC
If g++ is called with -V option and the only input files are objects and libraries, then the alternative driver called in chain cannot guess the language any more, forgets to put libstdc++ in the collect2 call, and the linker fails.

Release:
3.3, 3.4 (snapshots)

Environment:
gcc version 3.3 20030506 (prerelease); gcc version 3.4 20030509 (experimental); platform-independent

How-To-Repeat:
Take a little C++ (Hello, world!) program, compile and link it separately, specifying the -V option in both commands.
Comment 1 gawrilow 2003-05-09 16:06:00 UTC
Fix:
Probably, the installation script could create an extra hardlink 'machine-g++-version'; the driver could then insert its basename into the execvp() first argument instead of fixed '-gcc-'.  Or give along a -x option depending on the own basename.
Comment 2 Andrew Pinski 2003-05-24 20:08:10 UTC
confirmed on mainline 20030524)/3.3 experimental (20021216):
tin:~/src/gnu/gcctest>g++ -V3.3 testhello.cc -v
Reading specs from /home/gates/pinskia/linux/lib/gcc-lib/i686-pc-linux-gnu/3.3/specs
Configured with: /home/gates/pinskia/src/gnu/gcc/src/configure --target=i686-pc-linux-
gnu --enable-__cxa_atexit --prefix=/home/gates/pinskia/linux --enable-threads=posix --
enable-shared
Thread model: posix
gcc version 3.3 20021216 (experimental)
 /home/gates/pinskia/linux/lib/gcc-lib/i686-pc-linux-gnu/3.3/cc1plus -quiet -v -
D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=0 -
D_GNU_SOURCE testhello.cc -D__GNUG__=3 -quiet -dumpbase testhello.cc -auxbase 
testhello -version -o /tmp/ccNsI82O.s
GNU C++ version 3.3 20021216 (experimental) (i686-pc-linux-gnu)
        compiled by GNU C version 3.3 20021216 (experimental).
#include "..." search starts here:
#include <...> search starts here:
 /home/gates/pinskia/linux/include/c++/3.3
 /home/gates/pinskia/linux/include/c++/3.3/i686-pc-linux-gnu
 /home/gates/pinskia/linux/include/c++/3.3/backward
 /usr/local/include
 /home/gates/pinskia/linux/include
 /home/gates/pinskia/linux/lib/gcc-lib/i686-pc-linux-gnu/3.3/include
 /home/gates/pinskia/linux/i686-pc-linux-gnu/include
 /usr/include
End of search list.
 /home/gates/pinskia/linux/lib/gcc-lib/i686-pc-linux-gnu/3.3/../../../../i686-pc-linux-gnu/bin/
as -V -Qy -o /tmp/ccXwuSGD.o /tmp/ccNsI82O.s
GNU assembler version 2.14.90 (i686-pc-linux-gnu) using BFD version 2.14.90 
20030523
 /home/gates/pinskia/linux/lib/gcc-lib/i686-pc-linux-gnu/3.3/collect2 --eh-frame-hdr -m 
elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /home/gates/pinskia/
linux/lib/gcc-lib/i686-pc-linux-gnu/3.3/crtbegin.o -L/home/gates/pinskia/linux/lib/gcc-lib/
i686-pc-linux-gnu/3.3 -L/home/gates/pinskia/linux/lib/gcc-lib/i686-pc-linux-gnu/3.3/../../../../
i686-pc-linux-gnu/lib -L/home/gates/pinskia/linux/lib/gcc-lib/i686-pc-linux-gnu/3.3/../../.. /
tmp/ccXwuSGD.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /home/gates/pinskia/linux/lib/gcc-lib/
i686-pc-linux-gnu/3.3/crtend.o /usr/lib/crtn.o
/tmp/ccXwuSGD.o(.text+0x1b): In function `main':
: undefined reference to `std::cout'
/tmp/ccXwuSGD.o(.text+0x20): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& 
std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> 
>&, char const*)'
/tmp/ccXwuSGD.o(.text+0x49): In function `__static_initialization_and_destruction_0(int, 
int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccXwuSGD.o(.text+0x7a): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccXwuSGD.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
tin:~/src/gnu/gcctest>g++ -v
Reading specs from /home/gates/pinskia/linux/lib/gcc-lib/i686-pc-linux-gnu/3.4/specs
Configured with: /home/gates/pinskia/src/gnu/gcc/src/configure --target=i686-pc-linux-
gnu --enable-__cxa_atexit --prefix=/home/gates/pinskia/linux --enable-threads=posix --
enable-shared
Thread model: posix
gcc version 3.4 20030524 (experimental)
tin:~/src/gnu/gcctest>
Comment 3 Wolfgang Bangerth 2003-06-01 02:50:49 UTC
While the PR is certainly valid, -V is not really the recommended way
anymore to use different compilers. It was used, IIRC, in the time
frame of before gcc2.8 or so, and indeed the manual entry for -V
gives revealing clues about when this was useful:

  @item -V @var{version}
  @opindex V
  The argument @var{version} specifies which version of GCC to run.
  This is useful when multiple versions are installed.  For example,
  @var{version} might be @samp{2.0}, meaning to run GCC version 2.0.
  @end table

The way to go these days is to install different versions of gcc into
different directories.

I have the feeling that this will some day be "fixed" by obsoleting -V...

W.
Comment 4 Wolfgang Bangerth 2003-06-10 18:16:22 UTC
*** Bug 11143 has been marked as a duplicate of this bug. ***
Comment 5 Nathanael C. Nerode 2003-06-10 22:44:07 UTC
Or under different names (via program_transform_name), which is actually quite feasible.

I'm suspending this, since it's not going to be fixed in the forseeable future (except by obsoleting -V, which has been discussed).
Comment 6 Andrew Pinski 2003-09-08 04:26:18 UTC
-V was removed for a while (I forgot when) but it was put back and fixed up so it would 
work between 3.x's but it also has been not recommened to use -V any way.
Comment 7 Andrew Pinski 2003-11-13 17:49:15 UTC
*** Bug 13036 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2004-04-02 17:00:48 UTC
*** Bug 14825 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2004-06-11 13:17:53 UTC
*** Bug 15940 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2004-09-09 16:40:30 UTC
*** Bug 17375 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2005-01-18 14:22:40 UTC
*** Bug 19504 has been marked as a duplicate of this bug. ***
Comment 12 Joseph S. Myers 2010-05-22 17:55:55 UTC
-b and -V were removed:

2010-04-08  Manuel López-Ibáñez  <manu@gcc.gnu.org>

        PR 42485
        * doc/invoke.texi (-b,-V): Delete.
        * doc/tm.texi: Do not mention -b.
        * gcc.c (display_help): Delete -b and -V.
        (process_command): Delete -b and -V.
        * gcc.h (DEFAULT_SWITCH_TAKES_ARG): Delete -b and -V.