Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* Unix Linker understanding
@ 1998-11-26  5:00 Marco Guidi
  1998-11-27  5:00 ` Marco Guidi
  1998-11-27  5:00 ` Dan Pop
  0 siblings, 2 replies; 3+ messages in thread
From: Marco Guidi @ 1998-11-26  5:00 UTC (permalink / raw)



Iuse a Digital Unix compiler and linker , 
but I think the problem is the same on
all Unix systems

I have the following problem:

I write a very foolish program like the following

void main() {
    int i;
    i++;
}

and save it in a file, e.g. the a.c file.

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 ?
(An advice about  documentation will be very good).

My e-mail :
guidi@fanta.iet.unipi.it
guidi@pania.iet.unipi.it
guidi@pegasus.iet.unipi.it

Thanks,
Marco Guidi.






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unix Linker understanding
  1998-11-26  5:00 Unix Linker understanding Marco Guidi
@ 1998-11-27  5:00 ` Marco Guidi
  1998-11-27  5:00 ` Dan Pop
  1 sibling, 0 replies; 3+ messages in thread
From: Marco Guidi @ 1998-11-27  5:00 UTC (permalink / raw)



> Iuse a Digital Unix compiler and linker , 
> but I think the problem is the same on
> all Unix systems
> I have the following problem:
> I write a very foolish program like the following
> void main() {
>     int i;
>     i++;
> }
> and save it in a file, e.g. the a.c file.
> 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 ?
> (An advice about  documentation will be very good).
 
I got some answers but may be is better I explain better what I need.
I'm using the VxWorks OS on an Alpha AXPpci33 CPU but it seems that the
mathemathic library of my VxWorks version doesn't work correctly.
So I would try to link (without relocation) to my object files the 
standard mathemethic library of the Digital Unix compiler. Then I will
load my object files on the VxWorks OS (relocation will be done
automatically by the loader).
This is why I'm trying to understand how the linker works.

Thank you.
 My e-mail :
 guidi@fanta.iet.unipi.it
 guidi@pania.iet.unipi.it
 guidi@pegasus.iet.unipi.it

Marco Guidi




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unix Linker understanding
  1998-11-26  5:00 Unix Linker understanding Marco Guidi
  1998-11-27  5:00 ` Marco Guidi
@ 1998-11-27  5:00 ` Dan Pop
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Pop @ 1998-11-27  5:00 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-11-27  5:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-11-26  5:00 Unix Linker understanding Marco Guidi
1998-11-27  5:00 ` Marco Guidi
1998-11-27  5:00 ` Dan Pop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox