This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

linker not linking.....


I can compile a hello world .c program with "gcc hello.c" and it works
just fine. When I attempt to compile (and link) the same program with 
command line lib options the linker portion dies. Why am I doing this?
Please read on....


Examples:
bash-2.03$ gcc -nostdlib -L/usr/lib hello.c
/usr/libexec/elf/ld: warning: cannot find entry symbol _start; defaulting to
08048074
/tmp/ccU19430.o: In function `main':
/tmp/ccU19430.o(.text+0xf): undefined reference to `printf'
/tmp/ccU19430.o(.text+0x1f): undefined reference to `printf'
bash-2.03$ 

bash-2.03$ gcc -static -nostdlib -L/usr/lib \
-lalias -lalias_p -lc -lc_p -lc_pic -lcalendar -lcalendar_p -lcom_err \
-lcom_err_p -lcompat -lcompat_p -lcrypt -lcrypt_p -lcurses -lcurses_p \
-ldialog -ldialog_p -ldisk -ledit -ledit_p -lf2c -lf2c_p -lfl -lfl_p \
-lftpio -lftpio_p -lg++ -lg++_p -lgcc -lgcc_p -lgcc_pic -lgmp -lgmp_p \
-lgnuregex -lgnuregex_p -lipx -lipx_p -lkeycap -lkeycap_p -lkvm \
-lkvm_p -ll -ll_p -lln -lln_p -lm -lm_p -lmd -lmd_p -lmp -lmp_p \
-lmytinfo -lmytinfo_p -lncurses -lncurses_p -lobjc -lobjc_p -lopie 
-lopie_p -lpcap -lpcap_p -lreadline -lreadline_p -lrpcsvc -lrpcsvc_p \
-lscrypt -lscrypt_p -lscsi -lscsi_p -lskey -lskey_p -lss -lss_p \
-lstdc++ -lstdc++_p -ltelnet -ltelnet_p -ltermcap -ltermcap_p \
-ltermlib -ltermlib_p -lutil -lutil_p -lvgl -lvgl_p -lxpg4 -lxpg4_p \
-ly -ly_p -lz -lz_p  hello.c
/var/tmp/ccaCTG6m.o: Undefined symbol `___main' referenced from text segment
/var/tmp/ccaCTG6m.o: Undefined symbol `_printf' referenced from text segment
/var/tmp/ccaCTG6m.o: Undefined symbol `_printf' referenced from text segment
collect2: ld returned 1 exit status
bash-2.03$ 

when I specify "-bloadmap" I get the following output....

int main() {
        printf("Hello World!!!!!!!\n");
}
*Initialization*:1: warning: `__FreeBSD__' redefined
*Initialization*:1: warning: this is the location of the previous definition
# 1 "/var/tmp/ccWwDByf.i"
gcc: installation problem, cannot exec `cc1': No such file or directory
gcc: file path prefix `/usr/local/lib/gcc-lib/loadmap/2.95.2/' never used

I then ran "gcc -bloadmap hello.c" and received the exact same error although 
the code linked properly and the binary ran perfectly. 

I then went on to run the following....

bash-2.03$ ls /usr/lib/*o
/usr/lib/c++rt0.o       /usr/lib/crt0.o         /usr/lib/gcrt0.o
/usr/lib/kzhead.o       /usr/lib/kztail.o       /usr/lib/scrt0.o
/usr/lib/sgcrt0.o

bash-2.03$ gcc -nostdinc -nostdlib -I/usr/include -L/usr/lib -static hello.c \
/usr/lib/c++rt0.o /usr/lib/crt0.o /usr/lib/gcrt0.o /usr/lib/kzhead.o \
/usr/lib/kztail.o /usr/lib/scrt0.o /usr/lib/sgcrt0.o -lgcc -lc

/usr/lib/crt0.o: Definition of symbol `_dlopen' (multiply defined)
/usr/lib/crt0.o: Definition of symbol `_dlclose' (multiply defined)
/usr/lib/crt0.o: Definition of symbol `_dlerror' (multiply defined)
/usr/lib/crt0.o: Definition of symbol `___progname' (multiply defined)
/usr/lib/crt0.o: Definition of symbol `start' (multiply defined)
/usr/lib/crt0.o: Definition of symbol `_dlsym' (multiply defined)
/usr/lib/gcrt0.o: Definition of symbol `_dlopen' (multiply defined)
/usr/lib/gcrt0.o: Definition of symbol `_dlclose' (multiply defined)
/usr/lib/gcrt0.o: Definition of symbol `_dlerror' (multiply defined)
/usr/lib/gcrt0.o: Definition of symbol `___progname' (multiply defined)
/usr/lib/gcrt0.o: Definition of symbol `start' (multiply defined)
/usr/lib/gcrt0.o: Definition of symbol `_dlsym' (multiply defined)
/usr/lib/kztail.o: Undefined symbol `_input_len' referenced from text segment
/usr/lib/kztail.o: Undefined symbol `_input_data' referenced from text segment
/usr/lib/kztail.o: Definition of symbol `_malloc' (multiply defined)
/usr/lib/kztail.o: Definition of symbol `_free' (multiply defined)
/usr/lib/scrt0.o: Definition of symbol `___progname' (multiply defined)
/usr/lib/scrt0.o: Definition of symbol `start' (multiply defined)
/usr/lib/scrt0.o: Definition of symbol `_dlopen' (multiply defined)
/usr/lib/scrt0.o: Definition of symbol `_dlclose' (multiply defined)
/usr/lib/scrt0.o: Definition of symbol `_dlsym' (multiply defined)
/usr/lib/scrt0.o: Definition of symbol `_dlerror' (multiply defined)
/usr/lib/sgcrt0.o: Definition of symbol `_dlopen' (multiply defined)
/usr/lib/sgcrt0.o: Definition of symbol `_dlclose' (multiply defined)
/usr/lib/sgcrt0.o: Definition of symbol `_dlerror' (multiply defined)
/usr/lib/sgcrt0.o: Definition of symbol `___progname' (multiply defined)
/usr/lib/sgcrt0.o: Definition of symbol `start' (multiply defined)
/usr/lib/sgcrt0.o: Definition of symbol `_dlsym' (multiply defined)
/usr/lib/libc.a(malloc.o): Definition of symbol `_malloc' (multiply defined)
/usr/lib/libc.a(malloc.o): Definition of symbol `_free' (multiply defined)
collect2: ld returned 1 exit status
bash-2.03$ 

The reason I'm doing this is because I have received a source tree from a 
vendor and must compile and link a simple .c program against that include/lib
tree in order to drop the binary on their propriotary OS. I am not asking you
all to support me on a proprietary platform. I am simply asking you all to 
assist me in getting gcc to call ld with the appropriate flags so the hello.c
program will compile on libs other than /usr/lib (dir specified along with 
-nostdlib -L/libdir). 

What do I have to do to get the following to link against a directory
other than /usr/lib?
--------------------------
#include <stdio.h>
int main() {
        printf("Hello World!!!!!!!\n");
}
--------------------------
BTW, changing <stdio.h> to "stdio.h" only affects the compilation 
phase which is working fine when I specify "-nostdinc -I/usr/include".

Please reply to all. 

--
 Andrew Otwell, MSS Special Ops Recon/Surveillance/Developer
 desk 678.443.6271, aotwell@iss.net, http://www.iss.net

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]