Makefile for linking in a c routine that uses GTK: a solution

Charles D Hixson charleshixsn at earthlink.net
Fri Jul 27 09:46:59 PDT 2007


The Makefile:
CC = gcc -g -I/usr/include/gdk
CD = dmd
DMD_DIR = /usr/local/dmd
DLNK = -L$(DMD_DIR)/lib -lphobos -lpthread -lm

all:  test1

test1:  test1md.o test1a.o
	$(CC)	test1md.o test1a.o `pkg-config --libs gtk+-2.0` 
-L/home/charles/lib $(DLNK) -o test1

test1md.o:
	$(CD)  -c test1md.d  -oftest1md.o

test1a.o: test1a.c
	$(CC)  `pkg-config --cflags gtk+-2.0` -c test1a.c -o test1a.o

clean:
	

Thanks to all who helped me debug this.
P.S.:  This is the "hello world" routing from the GTK C 
tutorial.  For those who are curious:

test1md.d is:
extern(C)  int  test();

void  main()  {  test;  }

and test1a.c is:
#include	<gtk/gtk.h>

static	void	hello	(GtkWidget *widget,	gpointer data)
{	g_print	("Hello World\n");	}

static	gboolean	delete_event	(GtkWidget *widget,	GdkEvent 
*event,	gpointer data)
{	/*	returning TRUE means don't send the destroy signal	*/
	g_print	("delete event occurred\n");
	//return	TRUE;
	return	FALSE;
}

static	void	destroy	(GtkWidget *widget,	gpointer data)
{	gtk_main_quit();	}

int	test()
{	GtkWidget	*window;
	GtkWidget	*button;

	gtk_init	(NULL, NULL);

	window	=	gtk_window_new	(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window), "Testing, 
testing...1, 2, 3...");

	g_signal_connect	(G_OBJECT(window), "destroy", 
G_CALLBACK(destroy), NULL);

	gtk_container_set_border_width (GTK_CONTAINER(window), 10);

	button	=	gtk_button_new_with_label("Hello World");
	g_signal_connect (G_OBJECT(button), "clicked", 
G_CALLBACK(hello), NULL);
	gtk_container_add(GTK_CONTAINER(window), button);
	gtk_widget_show(button);
	gtk_widget_show(window);
	gtk_main();
	return	0;
}

//int main(int argc, char *argv[])
//{	return	test(argc, argv);	}


More information about the Digitalmars-d-learn mailing list