LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 12-24-2008, 05:43 AM   #1
koumodaki
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Rep: Reputation: 0
Linking errors


Hi,

I am new to programming with GTK and am trying to create a small test window. I am getting a linker errors. Can someone please suggets me a solution for this.

The code in my program is:

#include <gtk/gtk.h>

static GtkWidget *main_window;

static void destroy(GtkWidget *widget gpointer data)
{
gtk_main(quit);
}

int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(main_window), "Sasank");
g_signal_connect(G_OBJECT(main_window),"destroy",G_CALLBACK(destroy,NULL);
gtk_widget_show_all(GTK_WIDGET(main_window));
gtk_main();
return 0;
}

The code is compiled using => gcc -o my_window.cpp `pkg-config --cflags --libs gtk+-2.0`

The errors I get are:
/usr/lib/gcc/i586-suse-linux/4.3/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_event_request_motions'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_window_beep'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_color_to_string'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_threads_add_idle'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_threads_add_idle_full'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_window_thaw_toplevel_updates_libgtk_only'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_window_set_opacity'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_window_set_startup_id'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_threads_add_timeout'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_threads_add_timeout_full'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_window_freeze_toplevel_updates_libgtk_only'
/usr/lib/gcc/i586-suse-linux/4.3/../../../libgtk-x11-2.0.so: undefined reference to `gdk_notify_startup_complete_with_id'
collect2: ld returned 1 exit status
linux-ls4f:/ #

Regards
 
Old 12-24-2008, 11:11 AM   #2
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
You do not invoke correctly gcc. The correct invocation would be:

Code:
gcc -o my_window my_window.cpp `pkg-config --cflags --libs gtk+-2.0`
Then "my_window" will be an executable.

For my installation the code has some mistakes. It is "gtk_main_quit()" and for g_signal_connect the invocation is "g_signal_connect(G_OBJECT(main_window),"destroy",G_CALLBACK(destroy),NULL);" (NULL is the last parameter of g_signal_connect and not the seccond of G_CALLBACK).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
TCP SYN attack -Linking errors adityabhat6 Programming 1 03-26-2006 07:10 PM
Hello World linking Errors shotokan Programming 4 03-24-2006 04:16 AM
linking problems - 'undefined reference' errors back2morrie Programming 1 06-14-2005 08:02 AM
Linking errors dhanakom Programming 4 07-08-2003 02:12 AM
Linking errors dhanakom Linux - Newbie 4 07-07-2003 05:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 12:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration