如何使用 GCC 包含所需的 C 库?
我正在尝试从 本教程编译简单的 C 示例 在 Ubuntu 上使用 GCC。我必须使用什么作为 GCC 的参数才能包含 #include
所需的库?
I am trying to compile the simple C example from this tutorial on Ubuntu using GCC. What do I have to use as arguments for GCC to include the needed libraries for #include <libappindicator/app-indicator.h>
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您正在尝试制作 GTK 应用程序,并且以前的解决方案适用于任何地方,例如使用-l 选项和 -I 选项,
但是,对于 GTK 应用程序,您可以还可以使用 pkg-config 这使它更容易正如你的道路可以被预定义。
一个有趣的例子可以在
http://developer.gnome.org/gtk/2.24/gtk-compiling。 html
You are trying to make a GTK app, and the previous solutions are as applicable anywhere like using the -l option and -I option,
However, for GTK applications, you may also use pkg-config which makes it easier as your paths can be predefined.
An interesting example can be found in
http://developer.gnome.org/gtk/2.24/gtk-compiling.html
ubuntu/linux 中所有 C++ 包含文件(如库文件和头文件)的默认路径位于
/usr/include/c++/11
The default path for all c++ include files like library files and header files in ubuntu/linux are found in
/usr/include/c++/11
使用
-l
命令行选项。您可以使用-L
选项指定库搜索路径。例如:这会将
myprogram
与文件夹/home/me/foo/lib
中的静态库libfoo.a
链接起来。Use the
-l
command line option. You can specify the library search path with the-L
option. E.g:This will link
myprogram
with the static librarylibfoo.a
in the folder/home/me/foo/lib
.使用:
pkg-config将为
libappindicator
及其依赖项获取所需的包含和库标志。这假设已经安装了 libappindictaor-dev 软件包。Use:
pkg-config will fetch the required include and library flags for
libappindicator
and its dependencies. This assumeslibappindictaor-dev
package is already installed.如果您使用 apt-get、Synaptic Package Manager 等来获取 appindicator 库(相对于从源代码构建它),您是否使用仅安装
libappindicator1
软件包还是您还安装了libappindicator-dev
来获取libappindicator
头文件? Linux 软件包经常将运行时库与编译时标头分开。这样,只需要库来满足动态链接的人就不必安装不需要的标头。但由于您正在进行开发,因此需要这些标头,因此也需要 libappindicator-dev 包。If you used
apt-get
,Synaptic Package Manager
, etc. to get theappindicator
library (vs. building it from source), did you only install thelibappindicator1
package or did you also installlibappindicator-dev
to get thelibappindicator
header files? Linux packages very often have split the runtime libraries from the compile-time headers. That way people who only need the libraries to satisfy a dynamic link don't have to install unneeded headers. But since you're doing development you need those headers and therefore need thelibappindicator-dev
package as well.我所做的是:
What I do is: