make files linking and archive ***time critical***

I'm new to makefiles and have inherited some pretty complex ones.  I need to link a library (libmysub.a) and the objects to make a new library(libmymain.a) usind $(LD) and it seems to work OK until I think later to the new library(libmymain.a) and it has unresolved's to the (libmysub.a).  If i check the (libmymain.a) none of the .o from (libmysub.a) are there.  Do I need to use $(AR) to move the .o files from (libmysub.a) to (libmymain.a) and if so how?

jgreavesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bryanhCommented:
Please provide some details on how you are creating libmymain.a.  The only way I know to create a .a file is with 'ar', but you seem to imply you haven't used 'ar'.

If all you want to do is create an archive libmymain.a that contains all the members of libmysub.a plus some additional object modules, then you need to use ar -x to extract the members of libmysub.a and then use ar -r to add them and your other object modules to libmymain.a.  'man ar' for all the details.

Something that may come closer to what you want is to link your object modules to the libmysub.a members they reference and create a single output object module (which you could then stick in a .a archive if you want).  To do that, use the --relocateable option on Ld:

ld mymain.o -lmysub --relocateable -o mymainwithsubs.o
0
skianCommented:
# makefile for libsub.a
# put a.o and b.o into libsub.a archive
libsub.a: a.o b.o
     $(AR) cr $@ $+

# makefile for libmain.a
# copy all content of libsub.a and c.o into libmain.a
libmain.a : libsub.a(*.o) c.o
     $(AR) cr $@ $+




Stephane
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bryanhCommented:
I copied that code verbatim into a make file, then created files named a.o, b.o, and c.o, then did 'make libsub.a', then 'make libmain.a', and it worked fine.  'ar t libmain.a' shows that libmain.a contains a.o, b.o, and c.o.

What does it do for you?

That's a pretty weird rule, however.  It uses libsub.a as a list of files.  Most people would just use a make variable that lists those files and use that variable in the rules for both libsub.a and libmain.a.

By the way, $+ should be $^.  Doesn't make any difference here, though.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

skianCommented:
bryanh,

> What does it do for you?

I am not the person who asked the question. My post was a
_possible solution_. Sorry, my post wasn't clear...

> Most people would just use a make variable that lists
> those files and use that variable in the rules for both
> libsub.a and libmain.a

Yes this is the most widely used solution except when
the 2 libs are created by 2 separate makefiles.

Stephane
0
bryanhCommented:
skian:

Ah, thanks.  I wasn't paying attention.

>> Most people would just use a make variable that lists
>> those files and use that variable in the rules for both
>> libsub.a and libmain.a
>
>Yes this is the most widely used solution except when
>the 2 libs are created by 2 separate makefiles.

I would think in a case like that, the .o files that went into libsub.a are likely not in the same directory as the make file that makes libmain.a, and so this method would still be limited.
0
jgreavesAuthor Commented:
Worked great thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.