如何设置 GTK+ 以在 Ubuntu Linux 上使用 Code::Blocks 进行开发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5921460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to setup GTK+ to develop with Code::Blocks on Ubuntu Linux
提问by Chris Becke
I am trying to develop a GTK+ application on Ubuntu 11.4, using Code::Blocks.
我正在尝试使用 Code::Blocks 在 Ubuntu 11.4 上开发 GTK+ 应用程序。
www.gtk.org has instructions on building GTK+ from source, that looked complicated. But the Ubuntu package manager listed libgtk3-dev as a package that I installed.
www.gtk.org 有关于从源代码构建 GTK+ 的说明,看起来很复杂。但是 Ubuntu 包管理器将 libgtk3-dev 列为我安装的包。
Code::Blocks I installed using the Ubuntu Software Center.
Code::Blocks 我使用 Ubuntu 软件中心安装。
Using the Code::Blocks project wizard to create a GTK+ project, when I build, the project fails to compile "cannot find gtk/gtk.h".
使用 Code::Blocks 项目向导创建 GTK+ 项目,当我构建时,项目无法编译“找不到 gtk/gtk.h”。
Clearly the GTK include (and lib) folders are not added to the Code::Blocks search folders. I have located the relevant paths and files...
很明显,GTK 包含(和 lib)文件夹没有添加到 Code::Blocks 搜索文件夹中。我已经找到了相关的路径和文件...
Do I have to explicitly & manually add all the search paths to Code::Blocks' search paths? Or am I missing some installation step.
我是否必须明确并手动将所有搜索路径添加到 Code::Blocks 的搜索路径?或者我错过了一些安装步骤。
采纳答案by Chris Becke
Assuming that you have located and installed the correct package. As of 2011, the current package was libgtk-3-dev
then the pkg-config
tool can be used to extract the linker and compiler flags - and with proper escaping in the Code:Blocks settings can inject the correct settings automatically.
假设您已经找到并安装了正确的软件包。截至 2011 年,当前包是libgtk-3-dev
当时该pkg-config
工具可用于提取链接器和编译器标志的工具 - 并且在 Code:Blocks 设置中进行适当的转义可以自动注入正确的设置。
Open Code::Blocks Settings > Compiler and Linker Settings... and add the following under Global Compiler Settings > Compiler Settings > Other Options
打开 Code::Blocks Settings > Compiler and Linker Settings... 并在 Global Compiler Settings > Compiler Settings > Other Options 下添加以下内容
`pkg-config --cflags gtk+-3.0`
and add this to Global Compiler Settings > Linker Settings > Other Options
并将其添加到 Global Compiler Settings > Linker Settings > Other Options
`pkg-config --libs gtk+-3.0`
With the ` this has the effect of running the pkg-config tool calling --cflags gtk+-3.0
(or --libs) which, assuming libgtk3-dev is installed, injects the necessary search folders and lib directives onto the gcc command line.
使用 ` 这会运行 pkg-config 工具调用--cflags gtk+-3.0
(或 --libs),假设安装了 libgtk3-dev,它会将必要的搜索文件夹和 lib 指令注入 gcc 命令行。
As an alternative, developer.ubuntu.comlists Anjutaas a C/C++ IDE that can create GTK+ projects. As an alternative to Code::Blocks its far more polished as an Ubuntu IDE.
作为替代方案,developer.ubuntu.com将Anjuta列为可以创建 GTK+ 项目的 C/C++ IDE。作为 Code::Blocks 的替代品,它作为 Ubuntu IDE 更加精致。
Scratch that. Anjuta looses its sheen quickly.
抓那个。Anjuta 迅速失去光泽。