Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-02-26
6
Medium Priority
?
205 Views
Last Modified: 2012-05-04
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?

0
Comment
Question by:jgreaves
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:bryanh
ID: 8031237
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
 
LVL 1

Accepted Solution

by:
skian earned 2000 total points
ID: 8032838
# 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
 
LVL 5

Expert Comment

by:bryanh
ID: 8034621
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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 1

Expert Comment

by:skian
ID: 8035777
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
 
LVL 5

Expert Comment

by:bryanh
ID: 8035946
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
 

Author Comment

by:jgreaves
ID: 8042440
Worked great thanks
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question