Remove Unwanted Libraries - optimizing

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Remove Unwanted Libraries - optimizing
# 8  
Old 12-20-2009
It seems that earlier developers to save effort on there end included all libraries within our project workspace which would be around 500. Now we are coding a separate test module which includes some objects referenced in the makefile. We created a new makefile for same and inclusion of some libraries for generating binary is giving hundreds of 'undefined reference' symbol error.
# 9  
Old 12-20-2009
Are you using GNU Make? It has some tools builtin to find your dependencies, build static dependency files, and copious debug output. You can use these to achieve your goals.
# 10  
Old 12-20-2009
Though we are not using GNU make, but right now we are in dead need to know that amongst the 500 libraries if I using some of them then what are the others which I can remove from my new makefile.

Please provide some reference for same.
# 11  
Old 12-20-2009
Here is a genetic way of doing it

Use the nm utility to ouput the symbol table for your application. A 'T' in the second column indicates a function that is either defined in your source code or comes from a static library. A 'U' in the second column indicates a function that is included via a shared library. You then need to massage that list (listA) to remove all the functions that are defined within your source code.

Next write a script to nm each of your 500 libraries and construct a sorted list (listB) of library + function names.

Finally write a script which uses listB to update listA by adding a column containing the name of the library where that function is defined.

At this stage you should have a list of all the external functions used by your application together with the name of library which defined the function.

It is then a trivial exercise to figure out which libraries are not needed by the application.
# 12  
Old 12-25-2009
Thanks a lot. We do need one automated script that would do this all.
# 13  
Old 02-09-2010
Quote:
Originally Posted by uunniixx
This is what I want to avoid - hit and trial method, the problem will get worse when inclusion of one object / static library file I have another dependency. Further this will take lots of workload and days to drive it to completion
I don't think that trial/error would be so tough. In pseudo perl code:

Code:
my @all_libs  = split (/\s+/, `ls $LIBPATH/*.a`);
my $good_libs = "";

# get number of unresolved messages w/o any static lib:
my $n_symbols = `make target | grep 'unresolved' | wc -l`;
chomp ($n_symbols);

foreach my $lib ( @all_libs )
{
  # try to add that static lib, and see if the number of unresolved syms decreases

  $lib =~ s/^lib//;
  $lib =~ s/\.a$//;
  
  my $check = `/bin/env LDFLAGS=-l$lib make target | grep 'unresolved' | wc -l`;
  chomp ($check);

  if ( $check < $n_symbols )
  {
     # good lib, well done!
     $good_libs .= " -l$lib");
  }    
}

# we want to link against all good libs
print "$good_libs\n";

You may getting symbols resolved twice - but that is a situation you should have stumbled over previously, so I guess thats unlikely. In any case, that will be simplier then the more formal, and elegant Smilie, way via nm, which was proposed earlier.

The above won't work if some of your static libs depend on other static libs - in that case, you need to add those 'good' libs you found to the test linking step.

Last edited by Andre_Merzky; 02-09-2010 at 05:14 AM.. Reason: simplified code
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove unwanted white space

Hi, I have a very big file 25GB with information present in it like $ head ind_stats update index statistics pfirm001.dbo.Office using 200 values go ... (11 Replies)
Discussion started by: sam05121988
11 Replies

2. Shell Programming and Scripting

How to remove unwanted " from string...

I have this Input File with extra double quotes in the middle. Please suggest how to handle this condition. Input File: "123985","SAW CUT CONCRETE SLAB 20"THICK",,"98.57","","EACH","N" "204312","ARMAFLEX-1 3/8 X 3"",,"2.48","","PER FOOT","N" "205745","MISTING HEAD HOLLOW CONE "C"... (3 Replies)
Discussion started by: BICC
3 Replies

3. Shell Programming and Scripting

How to remove unwanted strings?

Hi Guys, Can someone give me a hand on how I can remove unwanted strings like "<Number>" and "</Number>" and retain only the numbers from the input file below. INPUT FILE: <Number>10050000</Number> <Number>1001340001</Number> <Number>1001750002</Number> <Number>100750003</Number>... (8 Replies)
Discussion started by: pinpe
8 Replies

4. Shell Programming and Scripting

remove unwanted text using perl

Hello..I have a text file that need to remove unwanted text. This is the original file. No. Time Source Destination Protocol Info 16 0.649949 10.1.1.101 209.225.11.237 HTTP POST /scripts/cms/xcms.asp HTTP/1.1 ... (9 Replies)
Discussion started by: taxi
9 Replies

5. Shell Programming and Scripting

Remove unwanted lines

I have a .xml file, where i need some output. The xml file is like: Code: <?******?></ddddd><sssss>234</dfdffsdf><sdhjh>534</dfdfa>......... /Code I need the output like: code 234 534 . . . /code How can i do it? (5 Replies)
Discussion started by: anupdas
5 Replies

6. Shell Programming and Scripting

awk - need to remove unwanted newlines on match

Context: I need to remove unwanted newlines from a data file listing books and associated data. Here is a sample listing ( line numbers included ): 1 360762| Skip-beat! 14 /| 9781421517544| nb | 2008.| Nakamura, Yoshiki.| NAKAMUR | Kyoko Mogami followed 2 her true love Sho to Tokyo to... (6 Replies)
Discussion started by: Bubnoff
6 Replies

7. Solaris

Remove unwanted packages

I got a system which was installed with SUNWCXall cluster installed on it and i want remove unwanted software like GMNOME, Java Desktop System, Staroffice and numerous other softwares .. i want to do an automated removal of these packages where its uninstalled by itself ..from the is there any... (4 Replies)
Discussion started by: fugitive
4 Replies

8. UNIX for Advanced & Expert Users

How to Remove the unwanted Blank Lines

I have a file with the below data, i would like to remove the end blank lines with no data. I used the below commands but could not able to succeed, could you please shed some light. Commands Used: sed '/^$/d' input.txt > output.txt grep -v '^$' input.txt > output.txt input.txt file... (5 Replies)
Discussion started by: Ariean
5 Replies

9. Shell Programming and Scripting

Remove unwanted XML Tags

I have set of sources and the respective resolution. Please advice how to resolve the same using Unix shell scripting. Source 1: ======= <ext:ContactInfo xmlns:ext="urn:AOL.FLOWS.Extensions"> <ext:InternetEmailAddress>AOL@AOL.COM</ext:InternetEmailAddress> </ext:ContactInfo> Resoultion... (1 Reply)
Discussion started by: ambals123
1 Replies

10. Shell Programming and Scripting

Remove unwanted data?

Hi Can any one help me remove the unwanted data? I would want to remove the complete event id 4910 ( the type there is INFO), that means, I have to remove starting from 7th - 19th lines. can any one of you please help? Thanks, (24 Replies)
Discussion started by: hitmansilentass
24 Replies
Login or Register to Ask a Question