我怎样才能知道哪些标志可供 GCC 更轻松地链接库?
在阅读某些库的文档时,我看到某些库有一些功能,例如使用这些库编译程序更容易,只需在 GCC 参数中键入“-something
”,而不是键入库的路径或使用 pkg (... -- cflag --clibs
)。
如何获取系统上当前安装的库或软件包的“-something
”列表?
例如,OpenGL 标志: -lGLUT -lGL
当我使用包管理器安装新库时,它们肯定存储在 GCC 的配置文件中,或者 GCC 如何知道如何使用它们?
While reading documentation on some library, I saw that some library have some feature, like compiling program using those library more easier, with just typing '-something
' in the GCC argument instead of typing the path to library or using pkg (... -- cflag --clibs
).
How can I get the list of those '-something
' for libraries or packages currently installed on my system?
For example, OpenGL flags:-lGLUT -lGL
They are surely stored in a GCC's config file when I use the package manager to install new library, or how GCC would know how to use them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些库不存储在任何配置文件中。
如果您检查 GCC 链接选项,您将看到选项“-l”用于选择要链接的库。该选项的作用是在指定路径中查找库。
如果您查看文件夹
/usr/lib
,您将看到许多名为/usr/lib/libgtkspell.so.0.0.0
的文件。这适用于名为 gtkspell 的库。您可以使用-lgtkspell
链接它,链接器在搜索文件时会自动添加其他部分。pkg-config
应用程序非常适合需要特殊额外 GCC 标志的库,无论是在编译 (--cflags
) 或链接 (--libs
) 时>)。但添加到编译/链接的实际标志pkg-config
只是标准 GCC 标志。Those libraries are not stored in any configuration file.
If you check the GCC link options you will see an option "-l" which is used to select libraries to link with. What that option does is to look for libraries in a specified path.
If you look in the folder
/usr/lib
you will see a lot of files named like/usr/lib/libgtkspell.so.0.0.0
. This if for a library named gtkspell. You link with it by using-lgtkspell
, the linker will automatically add the other parts when searching for the file.The
pkg-config
application is good for libraries that need special extra GCC flags, either when compiling (--cflags
) or linking (--libs
). But the actual flagspkg-config
adds to the compilation/linking are just standard GCC flags.我想知道那些标志,因为我不知道给 pkg 提供什么参数。
但我发现它是如何工作的:
在 /usr/lib/pkgconfig 中有我们需要的一切。仅将这些文件之一放入参数 + --cflag 和 --clib 中。
(我不知道我应该查看 /usr/lib/pkgconfig)
I wanted to know those flag, since i didn't know what argument to gave to pkg.
But i found out how it was working:
In /usr/lib/pkgconfig there is everything we need. Only put one of those file in argument, + --cflag and --clib.
(i didnt know i was suppose to look at /usr/lib/pkgconfig)