Linux Snippet: include a static library inside another static library
However a more "elegant" and easy solution would be to "incorporate" the secondary library inside your library as result to distribute one single library containing all required object files for compile. This can be done by extracting all the object files from the secondary library and include inside your library. In our example we'll call MyLibrary.a the library we just developed and SecondaryLibrary.a the library we require function from. All the required command will be included inside a shell script we can call addlib.sh as follow:
#!/bin/sh mkdir tmp cd tmp ar x ../SecondaryLibrary.a ar r ../MyLibrary.a * rm * cd .. rm -r tmp
As you can see the script create a temporary folder called tmp where extract all the object files from inside SecondaryLibrary.a and include all into the MyLibrary.a just compiled. At the end remove all object files and remove the temporary folder. This will allow MyLibrary.a to incorporate all the required objects for allow compilation distributing it standalone. Both SecondaryLibrary.a and MyLibrary.a need to be placed in the same position where the script file is executed. In case you use some IDE like, for example, Code::block you need to set the automatically execution of this script at the end of each compilation.
Comments
Post a Comment