Linking static libraries to other static libraries?

Static libraries do not link with other static libraries. The only way to do this is to use your librarian/archiver tool (for example ar on Linux) to create a single new static library by concatenating the multiple libraries.

Up vote 6 down vote favorite 7 share g+ share fb share tw.

I have a small piece of code that depends on many static libraries (a_1-a_n). I'd like to package up that code in a static library and make it available to other people. My static library, lets call it X, compiles fine.

I've created a simple sample program that uses a function from X, but when I try to link it to X, I get many errors about missing symbols from libraries a_1 - a_n. Is there a way that I can create a new static library, Y that contains X and all the functionality needed by X (selected bits from a_1 - a_n), so that I can distribute just Y for people to link their programs to? UPDATE: I've looked at just dumping everything with ar and making one mega-lib, however, that ends up including a lot of symbols that are not needed (all the .

O files are about 700 MB, however, a statically linked executable is 7 MB). Is there a nice way to include only what is actually needed? This looks closely related to How to combine several C/C++ libraries into one?.

C++ linker cmake ar . A link|improve this question edited Feb 3 '10 at 17:47 asked Jan 28 '10 at 20:14Jason Sundram1,76121331 73% accept rate.

Static libraries do not link with other static libraries. The only way to do this is to use your librarian/archiver tool (for example ar on Linux) to create a single new static library by concatenating the multiple libraries. Edit: In response to your update, the only way I know to select only the symbols that are required is to manually create the library from the subset of the .

O files that contain them. This is difficult, time consuming and error prone. I'm not aware of any tools to help do this (not to say they don't exist), but it would make quite an interesting project to produce one.

I've updated the question -- do you know any way of including only the . O files that are necessary? – Jason Sundram Jan 28 '10 at 21:16 Update -- If you find yourself wanting to do this, take a step back, and pursue something else (unless, as John Knoeller points out, you are using Visual Studio).

I sunk a lot of time into this approach and didn't get anything useful. – Jason Sundram Apr 12 '11 at 17:12.

If you are using Visual Studio then yes, you can do this. The library builder tool that comes with Visual Studio allows you to join libraries together on the command line. I don't know of any way to do this in the visual editor though.

Lib. Exe /OUT:compositelib. Lib lib1.

Lib lib2.lib.

A static library is just an archive of . O object files. Extract them with ar (assuming Unix) and pack them back into one big library.

I suggest you break up the libraries into separate object files. Let this be your repository. You can use your library tool to build a library containing only the object files that you need.

Many compilers will include a library all or nothing; so you get all the functions in the library whether you use them or not. Some linkers are better and they go to the file level. You get all the functions in the file whether they are used or not.

This may be a reason to have one function per file. I don't know of a librarian tool that will resolve symbols and output a new library containing only resolved functions. Perhaps there is one, but it is not a highly used application.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions