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

Comments:

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.

Posted by UX-admin on October 11, 2008 at 03:01 PM CST #

Correction:

-L/usr/lib/64 -R/usr/lib/64

Posted by UX-admin on October 11, 2008 at 03:02 PM CST #

Yes, you are right. I just separate the steps for who want to write makefile.
Thanks for your comments ! :)

Posted by xue on October 11, 2008 at 03:10 PM CST #

Post a Comment:
Comments are closed for this entry.
About

williamxue

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today