Proper way to link a static library using GCC

后端 未结 4 785
逝去的感伤
逝去的感伤 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:41

    The correct way to link a static library is using -l, but that only works if the library can be found on the search path. If it's not then you can add the directory to the list using -L or name the file by name, as you say.

    The same is true for shared libraries, actually, although they're more likely to be found, perhaps.

提交回复
热议问题