Code::Blocks and undefined references

I'm pretty much a beginner on C/C++ programming. I've taken classes in the past, and the language itself is not the biggest problem, it's the background infrastructure. I'm on a Linux box, trying to compile a gtk form generated by Code::Blocks. None of my own code in it yet.

I had to go into search directories and set up several include and lib directories so it could even get this far. So, after dealing with it not being able to find several header files, I get the following, which is just a snippet of 20 or more undefined references.

Here are the errors. I put the actual code down below.


||=== Build: Debug in Contacts (compiler: GNU GCC Compiler) ===|
obj/Debug/main.o||In function `helloWorld':|
/home/david/Documents/Contacts/Contacts/main.c|8|undefined reference to `gtk_window_get_type'|
/home/david/Documents/Contacts/Contacts/main.c|8|undefined reference to `g_type_check_instance_cast'|

Any idea how to deal with this? I looked up something about pkg-config, but it is slightly over my head at the moment.

Also, I assigned all those search directories to the project I'm working on now. I'm pretty sure they'll need to be reassigned for other projects. How to do that once? I don't see a way to set it for Code::Blocks itself.

Here is the code:

static void helloWorld (GtkWidget *wid, GtkWidget *win)
{
GtkWidget *dialog = NULL;

dialog = gtk_message_dialog_new (GTK_WINDOW (win), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "Hello World!");
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}

int main (int argc, char *argv[])
{
GtkWidget *button = NULL;
GtkWidget *win = NULL;
GtkWidget *vbox = NULL;

/* Initialize GTK+ */
g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
gtk_init (&argc, &argv);
g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

/* Create the main window */
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (win), 8);
gtk_window_set_title (GTK_WINDOW (win), "Hello World");
gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
gtk_widget_realize (win);
g_signal_connect (win, "destroy", gtk_main_quit, NULL);

/* Create a vertical box with buttons */
vbox = gtk_vbox_new (TRUE, 6);
gtk_container_add (GTK_CONTAINER (win), vbox);

button = gtk_button_new_from_stock (GTK_STOCK_DIALOG_INFO);
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (helloWorld), (gpointer) win);
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
g_signal_connect (button, "clicked", gtk_main_quit, NULL);
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

/* Enter the main loop */
gtk_widget_show_all (win);
gtk_main ();
return 0;
}





Thanks for any help.

David
Last edited on
Project -> Build options...
In 'Compiler settings' -> 'Other compiler options' write
`pkg-config --cflags gtk+-3.0`

In 'Linker settings' -> 'Other linker options' write
`pkg-config --libs gtk+-3.0`



> I'm pretty sure they'll need to be reassigned for other projects.
> How to do that once?
After configuring the options
File -> Save project as template...
Then you should see it in `User templates' when choosing to create a new project.
Ok. I tried the save as templates, and I get a box that says "Enter Title", but it won't let me enter anything, and won't close either. I have to reboot to get things back to where I can work. I've been running into a few things like with with Code::Blocks.

But, main problem solved. Many thanks.
Topic archived. No new replies allowed.