Trouble Importing Tkinter in embedded C program

David Boddie davidb at
Fri Nov 21 02:54:17 CET 2003

r_olson at (Rick Olson) wrote in message news:<a5d3ff08.0311191251.4cf92c24 at>...

> Thanks for the suggestion.

No problem.

> I tried to check the FAQ and newsgroup, but was unsuccessful.  I may
> well have missed it.  I'm not a serious programmer and am frequently
> unclear on exactly how to compile, link...

Sorry, it was more of a general "wondering out loud" comment, not a request
for you to do more work. ;-)

> Nevertheless, I tried linking by changing the makefile a
> few different ways all of which amount to the makefile below.  FWIW if
> I drop the definition of DLL this makefile will compile and run the
> examples in Extending and Embedding the Python Interpreter.

I'll work through this in pieces and try to see what could be causing the

> CC = gcc
> PY = /usr/include/python2.2
> PYLIB = /usr/lib/python2.2/config/libpython2.2.a

You could also try /usr/lib/ if it exists, but I don't think that
it will make much difference.

> PYINC = -I/usr/include/python2.2 -I/usr/include
> # Compiler flags
> OPT=		-g
> LIBS=	-L/usr/lib \
> 	-L/usr/X11R6/lib \
> 	-ltk8.4 -ltcl8.4 -lnsl -lX11 -ldl -lreadline -lieee -lpthread -lutil

You probably won't need the -ltk8.4 -ltcl8.4 and -lX11 libraries to be included
explicitly unless your main application requires them. 

> LDFLAGS=-Xlinker -export-dynamic
> DLLS=	/usr/lib/python2.2/lib-dynload/

I'm sure you meant at the end, there. ;-)

> testtk:	testtk.o
> 	$(CC) $(LDFLAGS) testtk.o $(DLLS) $(ALLLIBS) $(OPT) -o testtk
> testtk.o:	testtk.c
> 	$(CC) testtk.c -c $(OPT) $(PYINC)

I quickly put together an test program which embeds a TCL/Tk enabled Python
interpreter. Noting that I'm using Python 2.3, installed in /usr/local, my Makefile
reads like this (I apologise in advance to any Makefile experts reading this):

PREFIX = /usr/local
PYINCLUDE = -I$(PREFIX)/include/python$(PYVERSION)
PYLIB = -L$(PREFIX)/lib/libpython$(PYVERSION).so \
	-lpython$(PYVERSION) \
	-ldl -lpthread -lutil -lm \

default: all
%.o:	%.c
	gcc -c -fPIC $(PYINCLUDE) $<

all:	main

main:	main.o
	gcc $< $(PYLIB) -o main

	rm -f *~ *.o *.so core core.* main

Of course, some of this changes depending on your system's configuration
but, if you still have problems after applying some of the above ideas, then
I'll send you the example to look at.

Have fun,


More information about the Python-list mailing list