Hi Ian, Thank you for your reply.
Ian Lance Taylor wrote:
Jon Grant <j...@jguk.org> writes:
I see that some of the files are located in the -L library directory
specified, crtbegin.o, crtend.o in which case, perhaps they both do
not need their full long path specified.
Most linkers do not use the -L path to search for file names on the
command line.
OK.
Also I notice lots of duplicate parameters:
Is this directory really needed twice?
-L/usr/lib/gcc/i486-linux-gnu/4.3.3 -L/usr/lib/gcc/i486-linux-gnu/4.3.3
No. I would encourage you to investigate why it is happening.
i tried: gcc -o t -Wl,-debug test.c, I see collect2 gets the
duplicates passed to it, and then it passes it on to ld. I would have
thought that if collect2 was compiled with define
LINK_ELIMINATE_DUPLICATE_LDIRECTORIES it would strip out the duplicate
parameters before calling ld. It does not appear to be switched on in
this Ubuntu package I am using though. Is it on by default?
No. It was introduced only to avoid an error in the linker in some
version of SGI Irix. Generally the duplicate -L option does no harm.
I was actually thinking along of the lines of eliminating it earlier
in the process. Why does the directory get in there twice in the
first place?
OK, yes I agree, the earlier the better. However, I don't (yet) know
enough about GCC, also, don't have time to scratch this itch currently.
To see what collect2 is doing, use -Wl,-debug
If I add this to my existing command line I see there not any output:
$ gcc -### -o t -Wl,-debug test.c
If I change to not have -### I see it does work, not sure why.
-### controls the gcc driver, not the collect2 program.
Ok, I realised -### means the commands are not executed, which
explains why collect2 output was not visible.
So I understand that this passes -debug to collect2. As collect2 only
has -v mode to display version. Would a patch to add --help to it be
supported? Also could describe something about collect2's purpose at
the top of that --help output.
I think that ordinary uses of -Wl,--help will expect to see the --help
option for the linker, not for collect2. That said, I think it would
be OK to add a --help option for collect2 which issued some output and
then went on to invoke the linker.
OK, I'll prepare a patch for this change. Also I'd like to add
--version alias of current -v too.
1) collect.c:scan_libraries may not find ldd, in which case it
displays message on output, and returns as normal. Should it not be
fatal if ldd is required?
It seems to me that it gives an error message, which should cause
collect2 to exit with a non-zero status. Does that not happen for
you? Note that ldd is only required on HP/UX.
Just checked again, you are correct.
2) in collect2.c:main "-debug" is checked, and variable debug set to 1
(perhaps that should be "true" to match the style of other flags)
Yes, and debug should be changed from int to bool.
Ok, I'll reply with a patch soon.
Something else, as there isn't a man page for collect2, could one be
created? I don't know if the -Wl,-debug option is documented somewhere
else currently. This is the only page I found:
http://gcc.gnu.org/onlinedocs/gccint/Collect2.html
Is there a way to get collect2 to save the temporary .c file it
generates to have a look at it? I believe it may be the __main()
function, with the -debug option it gives the attached
gplusplus_collect2_log.txt, looking at the [/tmp/ccyBAI9V.c] file
though it is empty, any ideas?
I'm trying to build GCC trunk, with this line below. I've installed
the mpfr, gmp and mpc dev packges for Ubuntu 9.10, so not sure where
to investigate next
$ ./configure --with-mpfr=/usr --with-gmp=/usr -with-mpc=/usr
[snip]
checking for correct version of mpfr.h... yes
checking for the correct version of mpc.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.2+ and MPC
0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations. Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also
http://gcc.gnu.org/install/prerequisites.html
Thank you for your help so far.
Please include my address in replies.
Cheers, Jon
j...@netbook:~/dev$ cat test.cpp
#include <string>
#include <stdio.h>
std::string hello("Hello world!");
int main(void)
{
printf("%s\n", hello.c_str());
return 0;
}
j...@netbook:~/dev$ g++ -Wl,-debug -o t test.cpp
Convert string
'/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/'
into prefixes, separator = ':'
- add prefix: /usr/lib/gcc/i486-linux-gnu/4.4.1/
- add prefix: /usr/lib/gcc/i486-linux-gnu/4.4.1/
- add prefix: /usr/lib/gcc/i486-linux-gnu/
- add prefix: /usr/lib/gcc/i486-linux-gnu/4.4.1/
- add prefix: /usr/lib/gcc/i486-linux-gnu/
- add prefix: /usr/lib/gcc/i486-linux-gnu/4.4.1/
- add prefix: /usr/lib/gcc/i486-linux-gnu/
Convert string
'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games' into
prefixes, separator = ':'
- add prefix: /usr/local/sbin/
- add prefix: /usr/local/bin/
- add prefix: /usr/sbin/
- add prefix: /usr/bin/
- add prefix: /sbin/
- add prefix: /bin/
- add prefix: /usr/games/
Looking for 'real-ld'
Looking for 'collect-ld'
Looking for 'ld'
Looking for 'ld'
Looking for 'gnm'
Looking for 'gnm'
Looking for 'nm'
Looking for 'nm'
Looking for 'gstrip'
Looking for 'gstrip'
Looking for 'strip'
Looking for 'strip'
Looking for 'g++'
Looking for 'g++'
collect2 version 4.4.1 (i386 Linux/ELF)
ld_file_name = /usr/bin/ld
c_file_name = /usr/bin/g++
nm_file_name = /usr/bin/nm
strip_file_name = /usr/bin/strip
c_file = /tmp/ccyBAI9V.c
o_file = /tmp/ccQFkOYH.o
COLLECT_GCC_OPTIONS = '-o' 't' '-shared-libgcc' '-mtune=generic' '-march=i486'
COLLECT_GCC = g++
COMPILER_PATH =
/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/
LIBRARY_PATH =
/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/4.4.1/:/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../:/lib/:/usr/lib/:/usr/lib/i486-linux-gnu/
/usr/bin/ld --build-id --eh-frame-hdr -m elf_i386 --hash-style=both
-dynamic-linker /lib/ld-linux.so.2 -o t -z relro
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crti.o
/usr/lib/gcc/i486-linux-gnu/4.4.1/crtbegin.o
-L/usr/lib/gcc/i486-linux-gnu/4.4.1 -L/usr/lib/gcc/i486-linux-gnu/4.4.1
-L/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib -L/lib/../lib
-L/usr/lib/../lib -L/usr/lib/gcc/i486-linux-gnu/4.4.1/../../..
-L/usr/lib/i486-linux-gnu /tmp/ccClpCtg.o -lstdc++ -lm -lgcc_s -lgcc -lc
-lgcc_s -lgcc /usr/lib/gcc/i486-linux-gnu/4.4.1/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crtn.o
[Leaving /tmp/ccyBAI9V.c]
[Leaving /tmp/ccQFkOYH.o]
j...@netbook:~/dev$