Fedora Linux Support Community & Resources Center
  #1  
Old 7th March 2007, 04:51 PM
c_07 Offline
Registered User
 
Join Date: Feb 2007
Posts: 42
Exclamation Quick Tip #1 for New GTK+ Programmers

After drafting my first program using the GTK+ library:

Code:
#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;
}
I tried to compile it:

Code:
[Cam@localhost simple]$ gcc simplewindow.cpp -o simplewindow `pkg-config --cflags --libs gtk+-2.0`
/tmp/ccpifIYo.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
After a little searching, I found that this was the result of using the C compiler (gcc) on a C++ project. The solution: Use G++!!!

Code:
[Cam@localhost simple]$ g++ simplewindow.cpp -o simplewindow `pkg-config --cflags --libs gtk+-2.0`
This was a simple enough fix, and a stupid error, but I thought it was confusing enough for a beginning linux programmer to post its solution

I intend to post on the various mountains I encounter while beginning my GTK+ linux programming journey... but meanwhile, I hope this helps you.
Reply With Quote
  #2  
Old 8th March 2007, 09:54 AM
ibbo's Avatar
ibbo Offline
Registered User
 
Join Date: Jun 2005
Location: Leeds
Posts: 1,264
It should not throw an error because gtk.h can and is used by both C and C++ programs. Your problem was you named your file .cpp and then used a c compiler and fed it a cpp file.

Thats what it complained about and not the use of c instead of cpp.
__________________
A Hangover Lasts A Day, But Our Drunken Memories Last A Lifetime
--
Linux user #349545
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCfdjyzXscddzQvlhBedAcD7qfKmHo==zx0H
Reply With Quote
  #3  
Old 8th March 2007, 01:55 PM
mwette Offline
Registered User
 
Join Date: Nov 2005
Location: Los Angeles area
Posts: 887
Well, the file looks like C so if you would have ended it with .c instead of .cpp it would have worked.
Code:
$ gcc simplewindow.c -o simplewindow `pkg-config --cflags --libs gtk+-2.0`
$

If you feed gcc a .cpp file it will use the c++ compiler but it won't pass in the correct libraries.
Reply With Quote
  #4  
Old 8th March 2007, 06:30 PM
c_07 Offline
Registered User
 
Join Date: Feb 2007
Posts: 42
Ah, I see.

Eventually I would have run into the same problem, though, because I am a C++ programmer, not a C programmer
Reply With Quote
Reply

Tags
gtk, programmers, quick, tip

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Numerical Programmers nardinc Programming & Packaging 36 11th March 2008 03:51 AM
IT students not want to be programmers then what? tech291083 Programming & Packaging 33 14th May 2007 12:54 PM
How many programmers do we have? Flounder Wibble 60 7th March 2007 07:51 PM
Crackheaded programmers Shadow Skill Wibble 15 19th July 2005 06:38 PM


Current GMT-time: 12:10 (Tuesday, 21-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat