如何确定pkg-config所需的库名称?专家如何解决这类难题?
Great question—this is such a common pain point, and no, none of us have all the library names memorized! I’ve definitely struggled with this exact issue with libraries like DLIB too. Here’s how I (and most folks in the dev community) figure it out:
Locate the .pc file directly
pkg-config relies entirely on.pcconfiguration files to recognize libraries. These files are usually stored in standard paths like/usr/lib/pkgconfig,/usr/local/lib/pkgconfig, or sometimes/usr/share/pkgconfig. Usefindto hunt for the file related to your library:find /usr/lib/pkgconfig /usr/local/lib/pkgconfig -name "*.pc" | grep -i dlibThe name of the
.pcfile (without the.pcextension) is exactly what you need to pass to pkg-config. For example, if you finddlib-19.9.pc, thenpkg-config --cflags dlib-19.9would work. If you don’t find any.pcfiles, that’s a clue you might be missing the development package for the library—on Debian/Ubuntu systems, this is usually something likelibdlib-dev(install it withsudo apt install libdlib-dev).Check for a library-specific config tool
Many libraries ship their own configuration scripts instead of (or in addition to) pkg-config support. For DLIB, try running:dlib-config --cflags --libsThis will spit out the exact compiler and linker flags you need, no pkg-config required. Tools like this are often named
[library]-config, so it’s worth trying that pattern.Use your package manager to trace the .pc file
If you’re on a system with a package manager (like apt, dnf, or brew), you can search for which package provides the.pcfile. For example, on Ubuntu:apt-file search dlib.pcThis will tell you which package includes the pkg-config file, and confirm the correct name you should use.
Don’t rely on ldconfig output alone
Theldconfig -pcommand shows you shared libraries available at runtime, but pkg-config uses the development metadata (the.pcfiles) which are part of the dev package. These are often separate, so the.sofilename doesn’t always map directly to the pkg-config library name.
At the end of the day, it’s all about knowing where to look for the metadata, not memorizing every possible library name.
内容的提问来源于stack exchange,提问作者puk

