You are not logged in.

#1 2005-06-04 19:12:37

starthis
Member
Registered: 2004-12-25
Posts: 46

GTK2 Linking

I have very little experience in programming GTK2, nevertheless I wanted to try it on archlinux.

After a 'pacman -S gtk2' (there seems to be no gtk2-devel package) I thought I was all set to compile a hello world example(http://www.gtk.org/tutorial/sec-compiling.html)...alas. 

While the pkg-config output for "pkg-config --cflags gtk+-2.0" and "pkg-config --libs gtk+-2.0" seems correct, I get a huge amount of errors.

It looks pretty much like this :

http://www.wer-weiss-was.de/theme158/ar … 69167.html

This was the only simular problem I could find online, unfortunatly I don't know how to apply the answer in that thread. (It suggests the linker can't find the gtk libraries)

Is there some configuration required after installing the gtk2 package? if so, I didn't find any documentation about it in forum/wiki. Since no one else posted this problem, I suppose normally it works out-of-the box?

All help is very appreciated. I'd love to see that hello world gtk2 example pop up wink

Offline

#2 2005-06-05 21:01:56

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: GTK2 Linking

arch has no separate devel packages as you already found out so i guess it should work, i haven't coded native gtk yet only pygtk and that has always worked for me without problems,


arch + gentoo + initng + python = enlisy

Offline

#3 2005-06-06 17:39:50

starthis
Member
Registered: 2004-12-25
Posts: 46

Re: GTK2 Linking

I also would assume it works without problems, it does on both suse and ubuntu.

Thats why I wonder if I'm the only one with this problem. Can anybody test if they can compile this hello world example?

Offline

#4 2005-06-06 18:27:24

iBertus
Member
From: Greenville, NC
Registered: 2004-11-04
Posts: 2,228

Re: GTK2 Linking

I followed your links and copy-pasted helloworld.c into a text editor, saved it and compiled it without problem. I used the following to compile it:

gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`

I did make sure that everything was on one line in the console, however.

Offline

#5 2005-06-06 18:30:53

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: GTK2 Linking

starthis, can you post the exact code and erros you're getting... usually when you get spam like that from header files, it's something like a missing semicolon or some odd syntax error that mucks everything up

Offline

#6 2005-06-07 19:23:06

starthis
Member
Registered: 2004-12-25
Posts: 46

Re: GTK2 Linking

The problem seems to be that many of the /usr/include dirs are not readable for the users group. It seemed that this was the problem. As root it compiled fine.

I started changing the permissions in /usr/X11R6/include and /usr/include,
but it seems there is still more to change.

I wonder how these perms can be set so wrong? I didn't alter them manually (eg. gtk2 was freshly installed). And they appear like this :


[starthis@morpheus X11R6]$ ls -al
total 28
drwxr-xr-x   6 root root 4096 2005-03-27 21:59 .
drwxr-xr-x  13 root root 4096 2002-09-04 18:07 ..
drwxr-xr-x   2 root root 4096 2005-03-31 17:19 bin
drwx------   6 root root 4096 2005-03-27 21:59 include
drwxr-xr-x   6 root root 8192 2005-04-09 18:52 lib
drwxr-xr-x   7 root root 4096 2005-02-18 17:41 man

After changing the permissions to 755 on the entire /usr/include  & /usr/X11R6/include all went fine  8)

Offline

#7 2005-06-08 00:10:54

neri
Forum Fellow
From: Victoria, Canada
Registered: 2003-05-04
Posts: 553

Re: GTK2 Linking

Well, I don't get any error related to permissions but pure errors in code:

tobias@buran learn_c]$ gcc -Wall -g 01_gtk2_test.c -o 01_gtk2_test `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
01_gtk2_test.c: In function 'main':
01_gtk2_test.c:10: warning: passing argument 2 of 'gtk_init' from incompatible pointer type
01_gtk2_test.c:12: error: incompatible types in assignment
01_gtk2_test.c:13: error: 'hauptfenster' undeclared (first use in this function)
01_gtk2_test.c:13: error: (Each undeclared identifier is reported only once
01_gtk2_test.c:13: error: for each function it appears in.)
01_gtk2_test.c:16: warning: control reaches end of non-void function

this is how I compiled it.

gcc -Wall -g 01_gtk2_test.c -o 01_gtk2_test `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`

get the same as root.

-neri

Offline

#8 2005-06-08 08:07:56

JGC
Developer
Registered: 2003-12-03
Posts: 1,664

Re: GTK2 Linking

That's an error in your code then. Could you post the main function that doesn't compile?

Offline

#9 2005-06-08 10:31:05

neri
Forum Fellow
From: Victoria, Canada
Registered: 2003-05-04
Posts: 553

Re: GTK2 Linking

JGC wrote:

That's an error in your code then. Could you post the main function that doesn't compile?

#include <gtk/gtk.h>

#define WID GtkWidget

void killall();

int main(int argc, char *argv[])
{
 WID p_MainWindow;
 gtk_init(&argc, argv);
 
 p_MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_signal_connect(GTK_OBJECT(hauptfenster), "destroy", GTK_SIGNAL_FUNC(killall), NULL);
 
 gtk_main();
}

void killall()
{
 gtk_main_quit();
}

well, I have no clue about native gtk2 stuff but 'hauptfenster' should be
'p_MainWindow' I guess. Anyway it gives me an error about somethin'
wrong in gtk_window_new() then. As I said, no idea abou gtk API smile

-neri

Offline

#10 2005-06-09 09:22:29

starthis
Member
Registered: 2004-12-25
Posts: 46

Re: GTK2 Linking

I will compile this example when I get home to be sure, but I think the code should compile fine with following changes :

int main(int argc, char *argv[])
{
 WID *p_MainWindow;
 gtk_init(&argc, argv);
 
 p_MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_signal_connect(GTK_OBJECT(p_MainWindow), "destroy", GTK_SIGNAL_FUNC(killall), NULL);
 
 gtk_main();
}

or

int main(int argc, char *argv[])
{
 WID p_MainWindow;
 gtk_init(&argc, argv);
 
 &p_MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_signal_connect(GTK_OBJECT(&p_MainWindow), "destroy", GTK_SIGNAL_FUNC(killall), NULL);
 
 gtk_main();
}

gtk_window_new() returns an address so you need a pointer.

Offline

Board footer

Powered by FluxBB