Proper way to link a static library using GCC

后端 未结 4 773
逝去的感伤
逝去的感伤 2020-12-24 13:56

Why is it that some static libraries (lib*.a) can be linked in the same way that shared libraries (lib*.so) are linked (ld -l switch), but some can not?

I had always

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 14:59

    The reason is historical. The "ar" tool was original the file archive tool on PDP11 unix, though it was later replaced entirely by "tar" for that purpose. It stores files (object files, in this case) in a package. And there's a separate extension containing the symbol table for the linker to use. It's possible if you are manually managing files in the archive that the symbol table can get out of date.

    The short answer is that you can use the "ranlib" tool on any archive to recreate the symbol table. Try that. More broadly, try to figure out where the corrupt libraries are coming from and fix that.

提交回复
热议问题