如何在生成文件中找到库的正确LDFLAG

How to find proper LDFLAG of a library in a Makefile?

本文关键字:LDFLAG 文件      更新时间:2023-10-16

当在Makefile中与LDFLAGS链接库时,如何知道库的名称?

例如:

libxml2.dylib 与 -lxml2 链接

libz.dylib实际上被命名为 zlib 与 -lz 相关联

这些标志在哪里指定?如何查找它们?

按照惯例,从库文件名中删除前面的"lib"。 对于名为"libmyspecial_library.so"的库文件,相应的标志为:

-lmyspecial_library

这实际上是 gcc 编译器的约定。 有关更多信息,请参见 gcc 手册页:

   -llibrary
      Use the library named library when linking.
      The  linker searches a standard list of directories
      for the library, which is  actually  a  file  named
      `liblibrary.a'.   The linker then uses this file as
      if it had been specified precisely by name....