For example, we have three following libraries:
1.1.......................lib_A.a
1.2.......................lib_B.a
1.3.......................lib_C.a
Now I want to create one library which consists of all the above static libraries.
I have used following command:
ar -crs lib_Z.a lib_A.a lib_B.a lib_C.a
When I create final executable with lib_Z.a, the compiler gives me the following error:
error adding symbols: archive has no index; run ranlib to add one
How to solve this issue?
Your
lib_Z.acontains no object files; it only contains other.afiles, and the loader doesn't know how to handle that. Runningranlibwouldn't help; it wouldn't find any object files in thelib_Z.aarchive. You have to extract the object files from the separate libraries and then build them all into the result:The only trouble you can run into is if two of the libraries contain the same object file name (e.g.
lib_A.acontainsconfig.oand so doeslib_B.abut they define different configurations). You would have to rename one (or both) of the object files: