From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,7869b04c4f1440fd X-Google-Attributes: gid1164f8,public From: Dan.Pop@cern.ch (Dan Pop) Subject: Re: Unix Linker understanding Date: 1998/11/27 Message-ID: #1/1 X-Deja-AN: 416239446 References: X-Complaints-To: news@sunnews.cern.ch X-Trace: sunnews.cern.ch 912183093 15415 (None) 137.138.32.79 Organization: CERN European Lab for Particle Physics Newsgroups: comp.sys.dec In Marco Guidi writes: >If I try to compile and link it with > > cc a.c > >I get an a.out executable file that I can run. > >But if I try to compile a.c with > cc -c a.c > >and then I try to link with > ld a.o -lc > >I get an a.out executable file, but when I run it >I get a Segmentation fault error. > >Is there anyone who can help me understanding why this not works ? The easy way is to not explicitly invoke ld yourself. Use cc to perform the linking, like this: cc a.o It you need/want to use ld, use the following command to discover how to correctly invoke ld for a C program: cc -v a.c The generated ld command might look like this: /usr/lib/cmplrs/cc/ld -g0 -O1 -call_shared /usr/lib/cmplrs/cc/crt0.o a.o -lc The magical ld incantation is fairly system specific, so people tend to avoid it and use cc instead. Dan -- Dan Pop CERN, IT Division Email: Dan.Pop@cern.ch Mail: CERN - EP, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland