bgroenks
bgroenks

Reputation: 1889

GTK+/GCC Crashing On Start

I'm trying to learn how to use GTK in C.

I'm developing using Eclipse CDT. I copied the following code from an examples website:

#include <gtk/gtk.h>
#include <stdlib.h>

void displayUI()
{
GtkWidget* mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

gtk_window_set_default_size(GTK_WINDOW(mainWindow), 400, 300);
gtk_window_set_title(GTK_WINDOW(mainWindow), "GTK Simple Example");
gtk_window_set_position(GTK_WINDOW(mainWindow), GTK_WIN_POS_CENTER_ALWAYS);

gtk_signal_connect(GTK_OBJECT(mainWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(mainWindow);
}

int main(int argc, char *argv[]) {

gboolean b = gtk_init_check(&argc, &argv);

if(b == 0) {
    puts("Failed to init");
    exit(0);
}

gtk_init(&argc, &argv);

displayUI();

gtk_main();

return EXIT_SUCCESS;
}

Every time I try to run this program (or anything else involving GTK, Windows immediately displays a "InsertProgramNameHere.exe has crashed" message.

I have MinGW, MinSYS, PKG-CONFIG and MAKE all properly installed. The program compiles fine... it just won't run.

Any ideas?

UPDATE

I found this error log. There seems to be a dependency problem.

Faulting application TestRun.exe, version 0.0.0.0, time stamp 0x4f839a6a, faulting

module libgtk-win32-2.0-0.dll, version 6.0.6002.18541, time stamp 0x4ec3e39f, exception 

code 0xc0000135, fault offset 0x0006f52f, process id 0x1674, application start time 

0x01cd16c174d3df90.

Upvotes: 4

Views: 1240

Answers (3)

KIRAN K J
KIRAN K J

Reputation: 732

You need to add the path to (MinGW, MinSYS and gtk-dev)'s bin folder in the environment variables.

Upvotes: 0

Hans Passant
Hans Passant

Reputation: 941465

exception code 0xc0000135

That is STATUS_DLL_NOT_FOUND. Gtk+ has a large number of dependent DLLs. Probably your best bet to get started is to use the all-in-one bundle and copy the entire content of the bin directory in the archive to your program's EXE directory. Crude but the docs are quite unapologetic about it:

Many of the developer files are relatively irrelevant. If you intend to redistribute the GTK+ run-time, you need to figure out which files you can leave out yourself

Upvotes: 4

liberforce
liberforce

Reputation: 11454

Are you sure your GTK installation directory is in your PATH ?

Upvotes: 1

Related Questions