简体   繁体   中英

gdk (gtk3) in codeblocks on windows 7

I have configured gtk3+ (I've changed gtk2+ to gtk3+) in codeblocks 13.2 on windows 7, and created new gtk+ (exmaple) project. This example projcet was compiled and works properly.

Next I included gdk:

#include <gdk/gdk.h>

But when I added the lines:

gdk_init(&argc, &argv);

GdkScreen *screen = gdk_screen_get_default();`

I got 2 errors:

undefined referrence to 'gdk_init' and
undefined referrence to 'gdk_screen_get_default'

Where is the problem? I'm looking for a concrete solution.

compilation log:

||=== Build: Debug in gtk4test (compiler: GNU GCC Compiler) ===|
C:\myp\gtk4test\main.c||In function 'main':|
C:\myp\gtk4test\main.c|37|warning: 'gtk_vbox_new' is deprecated (declared at C:\gtk\include\gtk-3.0/gtk/deprecated/gtkvbox.h:60): Use 'gtk_box_new' instead [-Wdeprecated-declarations]|
C:\myp\gtk4test\main.c|53|warning: unused variable 'screen' [-Wunused-variable]|
obj\Debug\main.o||In function `main':|
C:\myp\gtk4test\main.c|52|undefined reference to `gdk_init'|
C:\myp\gtk4test\main.c|53|undefined reference to `gdk_screen_get_default'|
||=== Build failed: 2 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|

If you have already called gtk_init, then you shouldn't call gdk_init (as gtk_init also calls it). Generally, you should just call the gdk functions.

If you need gdk_init() for some reason, you will have to add

gcc ... `pkg-config --libs --cflags  gdk-3.0` ...

to the compilation line. Note that you probably also have to reconfigure your IDE to use gdk3 instead of gdk2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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