openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting » [help]gcc Compiler Option's Problem

Go Back   openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


ARCHIVES - Programming & Scripting A place to discuss website design, programming, shell scripts, etc

 
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 20-Jan-2008, 22:40
helloworld
Guest
 
Posts: n/a
Default

When I compile a hello.c in bash shell, I encounter a strange problem.

The hello.c's code is:
=============
#include <stdio.h>

int main()
{
printf("hello world\n");
return 1;
}
=============

the command line input is:
bash#gcc -o hello hello.c ->this action is successful

but when the input is:
bash#gcc -Wl, --verbose -o hello hello.c ->this command can not work well

the output of err is:
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.2.1 --enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.2 --enable-version-specific-runtime-libs --without-system-libunwind --with-cpu=generic --host=x86_64-suse-linux
Thread model: posix
gcc version 4.2.1 (SUSE Linux)
/usr/lib64/gcc/x86_64-suse-linux/4.2.1/cc1 -quiet -v hello.c -quiet -dumpbase hello.c -mtune=generic -auxbase hello -version -o /tmp/cchckHCi.s
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib64/gcc/x86_64-suse-linux/4.2.1/include
/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/include
/usr/include
End of search list.
GNU C version 4.2.1 (SUSE Linux) (x86_64-suse-linux)
compiled by GNU C version 4.2.1 (SUSE Linux).
GGC heuristics: --param ggc-min-expand=97 --param ggc-min-heapsize=126731
Compiler executable checksum: 15875aa798ad559dcc04a8709924cdb9
/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/as -V -Qy -o /tmp/ccBQYGbj.o /tmp/cchckHCi.s
GNU assembler version 2.17.50 (x86_64-suse-linux) using BFD version (GNU Binutils) 2.17.50.20070726-14 (SUSE Linux)
/usr/lib64/gcc/x86_64-suse-linux/4.2.1/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.2.1/crtbegin.o -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1 -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../.. /tmp/ccBQYGbj.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib64/gcc/x86_64-suse-linux/4.2.1/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64/crtn.o
/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/ld: : No such file: No such file or directory
collect2: ld returned 1 exit status

========
The most strange thing is when i divide the compile process into three steps below:
1) bash#/usr/lib64/gcc/x86_64-suse-linux/4.2.1/cc1 -quiet -v hello.c -quiet -dumpbase hello.c -mtune=generic -auxbase hello -version -o /tmp/cchckHCi.s ->success
2) bash#/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/as -V -Qy -o /tmp/ccBQYGbj.o /tmp/cchckHCi.s ->success
3) bash#/usr/lib64/gcc/x86_64-suse-linux/4.2.1/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.2.1/crtbegin.o -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1 -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../.. /tmp/ccBQYGbj.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib64/gcc/x86_64-suse-linux/4.2.1/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64/crtn.o ->success

I can work very well by using the above steps and get the correct binary file---hello.
but why it fails as i directly execute the command "gcc -Wl, --verbose -o hello hello.c"?

thanks for any advices!
  #2 (permalink)  
Old 20-Jan-2008, 22:45
ken_yap
Guest
 
Posts: n/a
Default

You're meant to put some linker option after -Wl, See the man page for gcc.

If you don't have any option to give the linker, then don't use it.
  #3 (permalink)  
Old 20-Jan-2008, 23:12
helloworld
Guest
 
Posts: n/a
Default

Quote:
You're meant to put some linker option after -Wl, See the man page for gcc.

If you don't have any option to give the linker, then don't use it.
[/b]
Thanks your reply

I use the option -Wl, --verbose complied with gcc rule, and this question came from section 2 chapter 5 of "linux from scratch". the intention of this operation is to display all the library files linked by "ld".

I want to know why but not bypass it

Thank your reply at mid-night
  #4 (permalink)  
Old 20-Jan-2008, 23:21
ken_yap
Guest
 
Posts: n/a
Default

Then the LFS documentation is wrong. You probably only need the --verbose.

It's not midnight everywhere in the world.
  #5 (permalink)  
Old 20-Jan-2008, 23:40
helloworld
Guest
 
Posts: n/a
Default

Quote:
Then the LFS documentation is wrong. You probably only need the --verbose.

It's not midnight everywhere in the world.
[/b]
Gcc has the option --verbose, it display gcc version number and other information.
Ld also has the same option, it display link script and all the linked library files.
The option -Wl,<option> is used to pass <option> to linker.
so the command "gcc -Wl,--verbose " means passing the "--verbose" option to ld.

I have resolved this problem. The root cause is an unwanted space between "-Wl," and "--verbose".
  #6 (permalink)  
Old 22-Jan-2008, 18:26
Suser
Guest
 
Posts: n/a
Default

you should return 0 to the OS. Returning 1 tells the OS that an error occurred.
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2