From: Dan.Pop@cern.ch (Dan Pop)
Subject: Re: Unix Linker understanding
Date: 1998/11/27 [thread overview]
Message-ID: <danpop.912182563@news.cern.ch> (raw)
In-Reply-To: Pine.BSF.3.91.981126180446.22942A-100000@fanta.iet.unipi.it
In <Pine.BSF.3.91.981126180446.22942A-100000@fanta.iet.unipi.it> Marco Guidi <guidi@fanta.iet.unipi.it> 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
next prev parent reply other threads:[~1998-11-27 5:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-11-26 5:00 Unix Linker understanding Marco Guidi
1998-11-27 5:00 ` Dan Pop [this message]
1998-11-27 5:00 ` Marco Guidi
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox