?
Solved

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

Posted on 2003-02-26
6
Medium Priority
?
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

770 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