HELP - why isn't ld working 
Author Message
 HELP - why isn't ld working

Greetings.  Got a user with the following problem:

He has two source files, called ex5.c:

 #include <stdio.h>
 float input(void);
 main()
 {
     printf("The value entered equals: %f\n", input());
 }

and ex5a.c:

 float input(void)
 {
    float flop;
    printf("Enter a floating point number: ");
    scanf("%f", &flop);
    return flop;
 }

Under Solaris 2.4, SunOS 4.1.4, and AIX 4.1.3 if he does the following:

 gcc ex5.c ex5a.c

It produces a correctly executing a.out.  So far so good.

Again under all three operating systems, if he does the following instead:

 gcc -c ex5.c
 gcc -c ex5a.c

Everything compiles fine.  However, if he then tries to link them to
produce an executable with the following:

 ld ex5.o ex5a.o -lc

On Solaris 2.4 it produces a working a.out, but on SunOS 4.1.4 it produces
an a.out that core dumps with a segmentation fault, and on AIX 4.1.3 it
produces nothing but gives the error message

 ld: 0711-327 WARNING: Entry point not found: __start
 ld: 0711-244 ERROR: No csects or exported symbols have been saved.

I'm not a C programmer, so I don't have much of a clue what's going on here.
Does anyone have any idea why the ld command he used works under Solaris 2.4
but not under SunOS 4.1.4 or AIX 4.1.3?

Thanks,

Darryl Marsee                                   Unix Systems Administrator

http://www.*-*-*.com/ ~marseed      Embry-Riddle Aeronautical University
(904) 226-7081                                      Daytona Beach, Florida



Tue, 21 Jul 1998 03:00:00 GMT  
 HELP - why isn't ld working


Quote:
> ld ex5.o ex5a.o -lc

>On Solaris 2.4 it produces a working a.out, but on SunOS 4.1.4 it produces
>an a.out that core dumps with a segmentation fault, and on AIX 4.1.3 it

Try using the GNU linker from the GNU binutils package.
--


Tue, 21 Jul 1998 03:00:00 GMT  
 HELP - why isn't ld working

Quote:
>Under Solaris 2.4, SunOS 4.1.4, and AIX 4.1.3 if he does the following:

> gcc ex5.c ex5a.c

>It produces a correctly executing a.out.  So far so good.

>Again under all three operating systems, if he does the following instead:

> gcc -c ex5.c
> gcc -c ex5a.c

>Everything compiles fine.  However, if he then tries to link them to
>produce an executable with the following:

> ld ex5.o ex5a.o -lc

>On Solaris 2.4 it produces a working a.out, but on SunOS 4.1.4 it produces
>an a.out that core dumps with a segmentation fault, and on AIX 4.1.3 it
>produces nothing but gives the error message

> ld: 0711-327 WARNING: Entry point not found: __start
> ld: 0711-244 ERROR: No csects or exported symbols have been saved.

The mistake is in using ld.  The correct way to link object files produced
by gcc is:

gcc ex5.o ex5a.o

gcc will produce the magic ld incantation needed to correctly link the
object files and produce an executable file on the underlying platform.
Use the -v option with the above command to see how this incantation looks
and you'll understand why the simple-minded ld invocation didn't work.

Quote:
>I'm not a C programmer, so I don't have much of a clue what's going on here.

Even if you aren't a C programmer you should have realized that this isn't
a C language issue and posting to c.l.c was a mistake.  A better place
would have been comp.unix.programmer.

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Tue, 21 Jul 1998 03:00:00 GMT  
 HELP - why isn't ld working

|> Greetings.  Got a user with the following problem:
|> He has two source files, called ex5.c:

<snip>

|> and ex5a.c:

<snip>

|> if he does the following:
|>
|>  gcc ex5.c ex5a.c
|>
|> It produces a correctly executing a.out.  So far so good.
|>
|> Again under all three operating systems, if he does the following instead:
|>
|>  gcc -c ex5.c
|>  gcc -c ex5a.c
|>
|> Everything compiles fine.  However, if he then tries to link them to
|> produce an executable with the following:
|>
|>  ld ex5.o ex5a.o -lc

Tell him don't do that ;-). Either stick with the first way or instead of
using ld use gcc with the command line:

gcc ex5.o ex5a.o

You can add the -lc, but it's probably not necessary.
--
"If it wasn't for C, we would be using BASI, PASAL, and OBOL."




Wed, 22 Jul 1998 03:00:00 GMT  
 HELP - why isn't ld working


Quote:

>|>  gcc ex5.c ex5a.c
>|>
>|> It produces a correctly executing a.out.  So far so good.
..
>|>  gcc -c ex5.c
>|>  gcc -c ex5a.c
...
>|>  ld ex5.o ex5a.o -lc

>Tell him don't do that ;-). Either stick with the first way or instead of
>using ld use gcc with the command line:

>gcc ex5.o ex5a.o

True enough, but why not at least give someone an idea of what
is going on!  The command "gcc ex5.o ex5a.o" does a lot more
than just call ld as "ld ex5.o ex5a.o -lc", and knowing what it
actually does might clear up a lot of confusion about the why
and when of various gcc command lines.

Darryl, try these to command lines to see what is happening, and
then you can post questions about what it is doing:

  gcc -v ex5.c ex5a.c

and

  gcc -c ex5.c
  gcc -c ex5a.c
  gcc -v ex5.o ex5a.o

The -v will cause verbose output from gcc, which means it will
show you the command lines it uses to call other programs,
including ld.  If nothing else it will convince you that calling
ld directly isn't as easy as using gcc to do it for you!  For
example:

tanana:floyd /tmp >gcc -v xx.o
Reading specs from /usr/lib/gcc-lib/i486-linux/2.7.0/specs
gcc version 2.7.0
 /usr/i486-linux/bin/ld -m elf_i386 -dynamic-linker \
 /lib/ld-linux.so.1 /usr/lib/crt1.o /usr/lib/crti.o \
 /usr/lib/crtbegin.o -L/usr/lib/gcc-lib/i486-linux/2.7.0 \
 -L/usr/i486-linux/lib xx.o -lgcc -lc -lgcc /usr/lib/crtend.o \
 /usr/lib/crtn.o

(The '\' characters are where I have wrapped the lines.)

Floyd

--



Thu, 23 Jul 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Why isn't this working?

2. Why isn't CListCtrl::SortItems working ?

3. Why isn't CRichEditCtrl working???

4. Why isn't GetMenuItemRect working as expected.

5. *Why isn't this working?????

6. Why isn't the SelectedIndexChanged working?

7. NULL isn't 0/0 isn't NULL

8. why isn't stdio full-duplex?

9. Top Left Icon - Why Isn't it Showing Up Correctly

10. Why isn't malloc necessary here?

11. why isn't there a strcasestr ?

12. Why isn't there a ->= operator?

 

 
Powered by phpBB® Forum Software