Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
integrate Tcl/Tk - C++

Posted by triclosan (triclosan), 18 October 2003
I have a ploblem!

How integrate Tcl/Tk and C++. For example - how use Tk interface with C++ console applications.

#include <iostream.h>
main() {
cout << "Helo" << '\n';
return 0;

For example how bind string 'Helo' with Tk field "Entry".

Posted by admin (Graham Ellis), 18 October 2003
Have a look at "Tcl and the Yk toolkit" by John Ousterhout - the author of the Tcl language ...;  there's about 100 pages there on the integration of Tcl and Tk into a C application, and it should work just as well for C++.  Tcl was designed as a library to integrate a scripting language into C ... it's not that hard to do.

Posted by triclosan (triclosan), 19 October 2003

But I need simple example of this integrate.
It can be not only for C++. If anybody can wrote anything for C please do it..

Posted by admin (Graham Ellis), 19 October 2003
Here's a simple example of extending Tcl by building an application with an interpretter in C, and extending the application with a command written in C.

/* Well House Consultant - building TCL into a C application */
/* Extended Tcl - an extra command written in "C" */

#include <stdio.h>
#include <tcl.h>

int equal(ClientData notneededhere, Tcl_Interp *ipointer,
   int eq_argc, char *eq_argv[]) {
   /* Should check argument count! */
   if (strcmp(eq_argv[1],eq_argv[2]) == 0) {
   ipointer->result = "1";
   } else {
   ipointer->result = "0";
   return TCL_OK;

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

   Tcl_Interp *myinterp;
   int status;

   printf ("Your Tcl Program will run ... \n");

   myinterp = Tcl_CreateInterp();
   (ClientData) NULL,
   (Tcl_CmdDeleteProc *) NULL);
   status = Tcl_EvalFile(myinterp,argv[1]);

   printf ("Your Tcl Program has completed\n");

It's the start of what you need; to bind your text field to a variable in C, you need to learn about the various variable types and data transfers between C and Tcl, and (as per previous post) the best way to find this is from John Ousterhout's book.  Please do post a follow up if you have any questions that relate to the examples in the book - I think there's only the one edition, so if you refer me by page number I'll be able to get straight to the point.

Posted by triclosan (triclosan), 20 October 2003
I have a ploblem.
My gcc compiler give :

[root@localhost CPP_igor]# gcc tcl.c
/tmp/ccYRRwKN.o: In function `main':
/tmp/ccYRRwKN.o(.text+0x5b): undefined reference to `Tcl_CreateInterp'
/tmp/ccYRRwKN.o(.text+0x79): undefined reference to `Tcl_CreateCommand'
/tmp/ccYRRwKN.o(.text+0x8f): undefined reference to `Tcl_EvalFile'
collect2: ld returned 1 exit status
[root@localhost CPP_igor]#

Please help to compile this source...

Posted by admin (Graham Ellis), 20 October 2003
Do you have the Tcl header file (tcl.h) loaded and in the correct path for gcc?

Posted by triclosan (triclosan), 20 October 2003
Yes I have it.
And I think tcl.h currently included into source...

Posted by admin (Graham Ellis), 21 October 2003
OK ... are you specifying any command line options to your compile to load in the tcl library (such as -ltcl)?

Posted by triclosan (triclosan), 21 October 2003
I add command line options and source is compiled correctly.
But now out is "Segmentation fault"...


Posted by admin (Graham Ellis), 22 October 2003
I'm guessing that you're running the program without any command line parameters.   This example is a tiny piece of code that's written to be easy to follow and understand, and it does not do any error checking.   Have a look at the code and work out what you need  

Posted by triclosan (triclosan), 22 October 2003
Thanks I try.

But i still don't understand how it working.
Anyway thanks a lot!

Posted by nash4 (nash4), 26 September 2007

sorry for my poor english, like you can see i'm not native speaker

i was looking at a topic with you and triclosan
i have some problems with integration of tcl/tk with c too

first i use code::blocks ide with mingw32 under windows
i'm medium programmer with c but beginner with code::blocks, and with gcc...(i never make a make manualy... )
i try to use the common dialogues of tcl/tk in a c program
i just found .lib
but it seems that mingw32 need .a library (but not always...)
do i need .lib or .a ?
i try to use reimp.exe, that reimplement the .lib like a .a but it seems odd...
the weight is not the same (  192 ko for tcl84.lib vs
                                              664 ko for libtcl84.a     may be a problem)

thus where can i found precompiled .a for windows
i try to found on web, to the site of sourcenet, but i dont find...
i would to compile tcl/tk thus i download source files
but it was "a little" more complicated that i thought...^^
too much for me indeed, i don't know where is the beginning^^ it is a very big projet...
thus i'm not sure of my reimplementation by reimp.exe

and once i have them, how to install, and how to configure ? (path that i have to give to the linker, compilator option, ...)(i gave every things that i can, but it seems that it doesn't make links...i certainly make a stupid thing but where)
it say
mingw32-gcc.exe: -ltk: linker input file unused because linking not done
mingw32-gcc.exe: -ltcl: linker input file unused because linking not done

it's very difficult to found information on tcl/tk with c on the web (and under windows and code::blocks !!!)

i compiled the code that you gave to triclosan
with adding this little code:
if (Tcl_Init(myinterp)!=TCL_OK)
   fprintf(stderr,"Tcl_Init failed: %s\n",myinterp->result);

the console program said:

Can't find usable init.tcl in the following directories:
this probably means that Tcl wasn't installed properly

i try to reinstall tcl/tk ( activetcl pack )
but the problem is still the same

i hope that i was enought clear, sorry if my questions are so beginner level, but i don't found answers for my questions anywhere
thanks a lot

Posted by smcool89 (smcool89), 13 November 2007
I am new to tcl and to this forum also.
I saw this forum i found that i found that the error mentioned in the questions from the man are exactly the  same as mine..
I have a small program written in c interacting with tcl and i don't know how to compile and use it .. I have tried several ways mentioned at different places and have got some errors .. below is the code and the errors i got while compiling it..

[sam@sam learning_c++_tcl]$ g++ c_tcl7.c
/tmp/ccgOFffj.o(.text+0x2d): In function `main':
: undefined reference to `Tcl_CreateInterp'
/tmp/ccgOFffj.o(.text+0x43): In function `main':
: undefined reference to `Tcl_EvalFile'
collect2: ld returned 1 exit status

Then i compiled it in the following way :

[sam@sam learning_c++]$ g++ c_tcl7.c -ltcl
/usr/bin/ld: cannot find -ltcl
collect2: ld returned 1 exit status

Please guide me how to remove the error and run the code perfectly.

Posted by admin (Graham Ellis), 13 November 2007
Hello.  See answer in other thread.   (There's no need to ask a question twice ...)

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho