简体   繁体   English

如何让GTK包含在C ++中工作?

[英]How do I get GTK includes to work for C++?

I am trying to start learning to develop GTK+ applications on Ubuntu 17.04 64-bit using C++ with the Eclipse CDT IDE, and I have been running into issues when trying to include the GTK library. 我正在尝试使用带有Eclipse CDT IDE的C ++在Ubuntu 17.04 64位上开始学习开发GTK +应用程序,并且在尝试包含GTK库时遇到了问题。 I am wondering why the includes aren't working. 我想知道为什么包含不起作用。 I have gtk 2.0 (DEV) installed, and recently installed gtk 3.0 to see if that would help to no avail. 我安装了gtk 2.0(DEV),最近安装了gtk 3.0,看看是否有帮助无济于事。 The following is my code: 以下是我的代码:

#include <iostream>
#include <gtk/gtk.h>

int main()
{
    return 0;
}

I am using the following compiler flags: 我使用以下编译器标志:

-I/usr/include/gtk-3.0 -I/usr/include/glib-2.0 -O0 -g3 -Wall -c -
fmessage-length=0

I am getting the following error from my compiler: 我从我的编译器收到以下错误:

g++ -I/usr/include/gtk-3.0 -I/usr/include/glib-2.0 -O0 -g3 -Wall -c -
fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.o" -o "main.o" 
"../main.cpp"
In file included from /usr/include/glib-2.0/glib/galloca.h:32:0,
             from /usr/include/glib-2.0/glib.h:30,
             from /usr/include/gtk-3.0/gdk/gdkconfig.h:13,
             from /usr/include/gtk-3.0/gdk/gdk.h:30,
             from /usr/include/gtk-3.0/gtk/gtk.h:30,
             from ../main.cpp:2:
/usr/include/glib-2.0/glib/gtypes.h:32:24: fatal error: glibconfig.h: 
No such file or directory
 #include <glibconfig.h>
                    ^
compilation terminated.
make: *** [main.o] Error 1
subdir.mk:18: recipe for target 'main.o' failed

Using pkg-config on the compiler flags, you need to include the gtk+-2.0 library and its dependencies. 在编译器标志上使用pkg-config,您需要包含gtk + -2.0库及其依赖项。 Adding this to your compiler command fixes the problem. 将此添加到编译器命令可以解决问题。

In Eclipse CDT, this can be found at Project Properties -> C/C++ Build -> Settings -> GCC C++ Compiler, and then editing the "Command". 在Eclipse CDT中,可以在Project Properties - > C / C ++ Build - > Settings - > GCC C ++ Compiler中找到它,然后编辑“Command”。

g++ `pkg-config --cflags --libs gtk+-2.0`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM