GTK 2 static library


I am able to use GTK3 static library that I compiled on my PC. But I compiled GTK2 , I could not call it from my projects.

I followed it for GTK3 here and it’s equalent for GTK2:
GTK compiling

It works . On GTK2 playing with Clang compiler some times I get unknown <gtk/gtk.h> and sometimes the called functions like gtk_init(&argc, &argv);

What to do ?

First of all: are you aware that GTK2 is in deep maintenance mode and should not be used in newly written code?

GTK3 is tested using a static build, but GTK2 hasn’t been tested for that for a long time. Given that GTK2 is in deep maintenance mode, you’re basically on your own.

You need to use pkg-config --cflags --libs gtk+-2.0 to gather the compiler and linker flags needed to build GTK applications; that has not changed since 2001, and applies to any version of GTK from 2.0 onwards.

Yes, I know that GTK2 is obsolete. I am recently working on a open-source C project with a custom Makefile in Code::Blocks IDE. The project uses GTK2 code. But if compiles in about 6 seconds which is fast enough for me here. But for my Temp project I want to try GTK2 simplified code to ask about problems I face in coding the project.

I have followed my GTK2 example like following , is there anything to fix ?

IDE : Code::BLocks
Compiler : LLVM Clang
Build options : Append target options to project options.

Project build options/Compiler setting/Other compiler options :
pkg-config --cflags gtk+-2.0

Linker setting/ Link libraries : /home/mehdi/Documents/Code_Blocks_Projects/GTK2_SL/bin/Release/libGTK2_SL.a

Linker setting/Other linker options :
-L/usr/lib -L/usr/X11R6/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -lXi -lgdk_pixbuf-2.0 -lm -lpangox -lpangoxft -lXft -lXrender -lXext -lX11 -lfreetype -lpango -latk -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0
pkg-config --libs gtk+-2.0

  • Note that back ticks do not show for pkg-config here. But I used them in Code::Blocks.

It sounds like instead of asking how to compile GTK, you should be asking how to use Code::Blocks.

pkg-config is used during the configuration phase of compilation to determine the location of header files and libraries. It is commonly called as part of a build system, such as a configure script or a meson definition, though you can also use it from a command line like in the example you linked to. I don’t know how you incorporate that into Code::Blocks.

I already did some part. Now trying GTK2 from a “Global Compiler” I get:

clang -o bin/Release/Temp obj/Release/Main.o -m64 -lfftw3l -lcunit -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 -lXi -lgdk_pixbuf-2.0 -lm -lpangox -lpangoxft -lXft -lXrender -lXext -lX11 -lfreetype -lpango -latk -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype /home/mehdi/Documents/Code_Blocks_Projects/GTK2_SL/bin/Release/libGTK2_SL.a /usr/lib/x86_64-linux-gnu/libpangoxft-1.0.a -L/usr/lib -L/usr/X11R6/lib
/usr/bin/ld: cannot find -lpangox
/usr/bin/ld: cannot find -lpangoxft
/usr/bin/ld: cannot find -lpango
/usr/bin/ld: cannot find -latk
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Process terminated with status 1 (2 minute(s), 1 second(s))
6 error(s), 1521 warning(s) (2 minute(s), 1 second(s))

Even though I have these installed:

And some more libraries.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.