|
-
December 25th, 2005, 07:20 AM
#1
.lib from .lib
Greetings,
I have a .lib which is like 23MB and has a lot, and I mean a lot of functions in it. lets call this "A.lib". If I make an executable that uses a few functions from A.lib, then the compiler/linker knows to only include the code from A.lib that is needed into my new executable and as a result the size of the executable is small.
Now I want to make a .lib of my own which uses some of the functions of A.Lib. let's call the new library B.Lib. I include A.lib and its header, use the functios I need from A.lib in my code and then compile. The problem here is that the compiler/linker is not clever enough to copy only the code for the functions from A.lib that I need, and it copies the entire A.lib inside my B.lib. So B.lib is also over 23MB! Then if I make other libs such as C.lib and D.lib, that use B.lib, they are bigger than 23MB.
But, if I include B.lib, C.lib, or D.lib in an executable, the compiler knows to only use the code that is need and the executable is again small.
What is goingon? How come the compiler knows only to use the needed code only when compiling applications and not libraries? Is there some setting (VS.NET) that I have missed? Is there a work arround on this?
Thanks & happy holidays,
Aristotel
-
December 25th, 2005, 11:33 AM
#2
Re: .lib from .lib
 Originally Posted by greekgoddj
Greetings,
I have a .lib which is like 23MB and has a lot, and I mean a lot of functions in it. lets call this "A.lib". If I make an executable that uses a few functions from A.lib, then the compiler/linker knows to only include the code from A.lib that is needed into my new executable and as a result the size of the executable is small.
Now I want to make a .lib of my own which uses some of the functions of A.Lib. let's call the new library B.Lib. I include A.lib and its header, use the functios I need from A.lib in my code and then compile. The problem here is that the compiler/linker is not clever enough to copy only the code for the functions from A.lib that I need, and it copies the entire A.lib inside my B.lib. So B.lib is also over 23MB! Then if I make other libs such as C.lib and D.lib, that use B.lib, they are bigger than 23MB.
But, if I include B.lib, C.lib, or D.lib in an executable, the compiler knows to only use the code that is need and the executable is again small.
What is goingon? How come the compiler knows only to use the needed code only when compiling applications and not libraries?
How should it know. If you are creating a library B and link it against library A, that means to the compiler that all functionality provided by A should be provided by B as well. How should the compiler know, at the time of linking B, that you application, that will use library B (and thus implicitly library A) will not call any function within A that is not called by a function in B.
 Originally Posted by greekgoddj
Is there a work arround on this?
If you own the source of library A, you can link against only against the needed object files in A, thus leaving out code that is unrelated.
-
December 25th, 2005, 01:26 PM
#3
Re: .lib from .lib
 Originally Posted by treuss
How should it know. If you are creating a library B and link it against library A, that means to the compiler that all functionality provided by A should be provided by B as well. How should the compiler know, at the time of linking B, that you application, that will use library B (and thus implicitly library A) will not call any function within A that is not called by a function in B.
If you own the source of library A, you can link against only against the needed object files in A, thus leaving out code that is unrelated.
Well I guess I expected it to know just as it knows when compiling an executable that uses the library, and only code for functions used. Does that make an sense?
-
December 25th, 2005, 01:53 PM
#4
Re: .lib from .lib
A static library is not built by the linker. It's built by the librarian LIB. You can use LIB manually to extract .obj files from libraries and bundle them together as new libraries. The VS help files have all the command line options for LIB.
A LIB is just a collection of .obj files, similar to an archive (tar, zip, rar...). LIB just knows how to bundle and unbundle these archives. There is no requirement for a library to be self-contained in the sense that all external dependencies of objs in it must be satisfied within the library. So there's no place for the librarian to do any dependency checking either.
If you know which objs you need from a library, like I said, you can rebundle it manually. If you want all the objs used in the linking of a specific exe file, what you can do is get the linker to produce verbose output when producing the exe file. It will print all the symbols it linked and which .obj file was used to satisfy it. You can then cross this list with the content of a library in order to find out which objs in the library were used. This is tedious to do by hand, but if you really need it, you can write a little text-processor to do it.
-
December 25th, 2005, 06:06 PM
#5
Re: .lib from .lib
Great,
Thanks for that information.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|