public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Need help building & integrating library into target program
@ 1999-12-11  2:42 Stuart Summerville (Deimus)
  1999-12-31 22:24 ` Stuart Summerville (Deimus)
  0 siblings, 1 reply; 12+ messages in thread
From: Stuart Summerville (Deimus) @ 1999-12-11  2:42 UTC (permalink / raw)
  To: gcc-help

(Sorry for the repost - resent to maintain thread)

>It would be best to show us how you're trying to link against the
>library; knowing your platform would also be helpful.
>--ag
>

Hi Arthur,

Given that I have mylib.a in the current directory, I issue the command:

gcc -static -g -o rw startup_lib.a

to produce the rw executable. Then, issuing the command:

ldd rw

tells me that this dynamically linked executable is dependent on mylib.o. I
presume that as its linked statically, there shouldn't be any lib
dependence....

Tools used:
Solaris 2.5.1
gcc egcs-2.91.57 19980901 (egcs-1.1 release)
ld 2.8.1 (with BFD 2.8.1)

Also, mylib.a was created in the following manner:

gcc -MD -I../include -g -o init.o -c init.c
ar rv ../../../obj/mylib.a *.o

I've seen the same behaviour on two Sol251 boxes.

To contrast this, if I do the same thing on a Redhat Linux (5.2) box (gcc =
2.7.2.3, ld = 2.9.1 (with BFD 2.9.1.0.15)), it works fine. If statically
linked, ldd won't touch it (unlike the Solaris box, which still shows that
erroneous dependence) & it runs properly; if dynamically linked, ldd reports
that libc and ld-linux are linked but no mylib.a (or even mylib.o).

?

Some other questions:

1) does linking of libraries dynamically only affect files specified with
the -l switch to ld? Can a file specified as an ordinary object file to ld,
be dynamically linked in? eg. if I don't supply ld with the -static switch,
will archive files passed in the manner "ld -o myprog mylib.a ..." be
statically linked anyway?
2) Is there any use in my creating arcive/object files with the -shared
switch to ld? This seems to be a useful thing to do, but the ld manpage
suggests its not a common method anymore.

Thanks,

sTu.

----------------------------------------------
Stuart Summerville
Home: stus@deimus.com.au
Work: stuart.summerville@icpdd.neca.nec.com.au
----------------------------------------------

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: Need help building & integrating library into target program
@ 1999-12-11 12:14 Stuart Summerville (NEC)
  1999-12-31 22:24 ` Stuart Summerville (NEC)
  0 siblings, 1 reply; 12+ messages in thread
From: Stuart Summerville (NEC) @ 1999-12-11 12:14 UTC (permalink / raw)
  To: Gcc-Help@Gcc. Gnu. Org

>It would be best to show us how you're trying to link against the
>library; knowing your platform would also be helpful.
>--ag
>

Hi Arthur,

Given that I have mylib.a in the current directory, I issue the command:

gcc -static -g -o rw startup_lib.a

to produce the rw executable. Then, issuing the command:

ldd rw

tells me that this dynamically linked executable is dependent on mylib.o. I
presume that as its linked statically, there shouldn't be any lib
dependence....

Tools used:
Solaris 2.5.1
gcc egcs-2.91.57 19980901 (egcs-1.1 release)
ld 2.8.1 (with BFD 2.8.1)

Also, mylib.a was created in the following manner:

gcc -MD -I../include -g -o init.o -c init.c
ar rv ../../../obj/mylib.a *.o

I've seen the same behaviour on two Sol251 boxes.

To contrast this, if I do the same thing on a Redhat Linux (5.2) box (gcc =
2.7.2.3, ld = 2.9.1 (with BFD 2.9.1.0.15)), it works fine. If statically
linked, ldd won't touch it (unlike the Solaris box, which still shows that
erroneous dependence) & it runs properly; if dynamically linked, ldd reports
that libc and ld-linux are linked but no mylib.a (or even mylib.o).

?

Some other questions:

1) does linking of libraries dynamically only affect files specified with
the -l switch to ld? Can a file specified as an ordinary object file to ld,
be dynamically linked in? eg. if I don't supply ld with the -static switch,
will archive files passed in the manner "ld -o myprog mylib.a ..." be
statically linked anyway?
2) Is there any use in my creating arcive/object files with the -shared
switch to ld? This seems to be a useful thing to do, but the ld manpage
suggests its not a common method anymore.

Thanks,

sTu.

_________________________________________________________________________
Stuart Summerville                         NEC Australia Pty. Ltd.
ph: (+61 3) 9264-3090                      Integrated Comm Products (R&D)
fax:(+61 3) 9264-3841                      649-655 Springvale Road
e-mail: stuarts@icpdd.neca.nec.com.au      Mulgrave, VIC 3170, AUSTRALIA

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Need help building & integrating library into target program
@ 1999-12-10  0:21 Stuart Summerville
  1999-12-10 13:02 ` Arthur Gold
  1999-12-31 22:24 ` Stuart Summerville
  0 siblings, 2 replies; 12+ messages in thread
From: Stuart Summerville @ 1999-12-10  0:21 UTC (permalink / raw)
  To: help-gcc

Hi all,

I'm trying to build a custom library that is then integrated into other target
programs. I'm having problems linking the library into the final executable.

Here's the steps I've taken:
1) Compile to object file (using -c switch on gcc) each of the source files for
the library.
2) Archive the object files together in mylib.a. This is using 'ar rv mylib.a
*.o'.
3) Compile another source file (new_app.c) ready to use the library. Same
compilation as before, to an object file.
4) Link new_app.o with mylib.a, using gcc. I've tried passing in the -static
switch also. The output is new_app, which should also contains any required
functions from mylib.

All goes well until runtime, when ld.so.1 informs me that it couldn't open
mylib.o (as opposed to mylib.a) & that new_app has been killed.

Why is this happening? Where is it getting mylib.o from?

Another makefile I have aquired, that I've based my makefile on, takes one extra
step after creating mylib.a. It runs the following:

prompt> : mylib.a

This seems to fuction properly,and does change the file, somehow. The variable
used to hold this ':' keyword is called $(RANLIB) which suggests its generating
an index into mylib.a, but I'm not sure how this mapping (of ':' to ranlib or
'ar -s') is done, unless its prodding the make program to do so, somehow.

So far as I can tell, my makefile is manipulating the library file just as the
sample one is.

If necessary, can you suggest some methods of analysing mylib.a to look for
problems?

Thanks for any help,

sTu.


________________________________________________________________________
Stuart Summerville                     NEC Australia Pty. Ltd.
ph: (+61 3) 9264-3090                  Integrated Comm Products (R&D)
fax:(+61 3) 9264-3841                  649-655 Springvale Road Mulgrave
stuarts@<nospam>icpdd.neca.nec.com.au  VIC 3170, AUSTRALIA

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

end of thread, other threads:[~1999-12-31 22:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-11  2:42 Need help building & integrating library into target program Stuart Summerville (Deimus)
1999-12-31 22:24 ` Stuart Summerville (Deimus)
  -- strict thread matches above, loose matches on Subject: below --
1999-12-11 12:14 Stuart Summerville (NEC)
1999-12-31 22:24 ` Stuart Summerville (NEC)
1999-12-10  0:21 Stuart Summerville
1999-12-10 13:02 ` Arthur Gold
1999-12-12 14:14   ` Stuart Summerville
1999-12-12 15:56     ` Stuart Summerville
1999-12-31 22:24       ` Stuart Summerville
1999-12-31 22:24     ` Stuart Summerville
1999-12-31 22:24   ` Arthur Gold
1999-12-31 22:24 ` Stuart Summerville

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).