how to compile with gtk on OpenSolaris

For people who use gtk+ on OpenSolaris first time. When you compile the application which used gtk+ library, the necessary compile and link options must be used. But for gtk+, the options are too much to list them all. "pkg-config" is useful to help you compile.
This is a simplest gtk application example:

/*
* base.c
*/
#include <gtk/gtk.h>

int main( int argc, char *argv[] )
{
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_main ();
return(0);
}

compile as following step: 1>cc -c `pkg-config --cflags gtk+-2.0` base.c 2>cc -o base `pkg-config --libs gtk+-2.0` base.o

3 thoughts on “how to compile with gtk on OpenSolaris

  1. If you’re going through the front end (cc), then you don’t need to compile and link in separate steps.
    The example above is needlessly complex. The simpler version would be:
    cc -o base `pkg-config –cflags –libs gtk+-2.0` base.c
    assuming that "gtk+-2.0.pc" has been configured to provide the -L and -R switches with the correct values.
    Also, the example above would only work for generating 32-bit binaries.
    To generate a 64-bit binary, there would have to be /usr/lib/pkgconfig/64/gtk+-2.0.pc file with the -L/usr/sfw/lib/64 -R/usr/sfw/lib/64 values and the PKG_CONFIG_PATH would have to be set to /usr/lib/pkgconfig/64.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s