Version 2 of Invoking Tcl commands from C++

Updated 2003-07-02 13:36:04

Purpose: document what one needs to do in a C++ application to invoke Tcl script commands (i.e. ones without a directly invokable API).

[Can someone provide a pointer to some sample c++ code that interacts with Tcl?]

Example: TclODBC is an extension written in C++.

You can evaluate Tcl scripts, call Tcl functions and write new Tcl commands in C++ just like in C. The Tcl headers are safe for direct use in C++. The only gotcha for Extension writers is that the Init functions must be declared 'extern "C"' so that the compiler leaves their names alone for the load command.

Also with command-line compilers (like GCC) be sure to use the C++ compiler frontend (like g++) for linking so that you pick up the C++ runtime support automatically.

Obviously everybody that interfaces with Tcl from C++ encapsulates some of the Tcl objects in corresponding C++ classes. BR doesn't know of any effort yet to provide a standard all-purpose C++ wrapper for Tcl.


See also C++.