Example code for beginers in writting extensions... [tBuild package]

From: Georgios Petasis (petasis_at_iit.demokritos.gr)
Date: 11/28/03


Date: Fri, 28 Nov 2003 23:27:09 +0200

Hi all,

I have done a small update in the tBuild package and I have
also added a release at SF:

https://sourceforge.net/project/showfiles.php?group_id=41786&release_id=2005
59

What is tBuild? Its a small tcl-only extension that can be
used (hopefully) to easily compile and link (simple :-)) tcl
extensions. It requires VC++ under windows
and what ever compiled tcl under unix.
(Under unix the tclConfig.h and perhaps tkConfig.h
must be installed in order for tBuild to work).

However, the most interesting addition is a small
package that can be used to generate a small
tcl extension. I wrote it in the process of
testing tBuild. There is also a small
test script, that generates such an extension.
Along with the extension, a tcl script for
building the extension is automatically created.

Creating an empty tcl extension (that does
nothing but it can be compiled and loaded in
Tcl) is quite easy:

package require tBuild::Extension
::tBuild::tExtension::CreateTclExtension \
          -pkgName testExtension \
          -pkgDir [pwd] \
          -cmdSpec {tBuildTest Test}

Studying this sample extension can be a good
exercise for those who want to develop their
first extension :-)

Compiling the extension is as easy as:

set OBJS [::tBuild::CompileSharedObject -define BUILD_%pkgNameUpper% \
                                        -includedir generic \
                                         generic/tcl%pkgName%.c \
                                         generic/%pkgName%.c]
eval ::tBuild::LinkSharedLibrary \
  -output lib/$binDir/lib%pkgName%[info \
   sharedlibextension] $OBJS

(Of course the compilation script is automatically
generated during the extension creation.)
I hope some of you will find it usefull...

George



Relevant Pages

  • How to cope with version conflicts? (was: version conflict for package "Tcl": TCL_VERSION vs TCL_PAT
    ... I recommend the latter in both cases. ... I wrote a Tcl/Tk extension which calls Tk_PhotoExpand. ... Tk_PhotoExpandchanged between Tcl 8.4 and 8.5: ... If I compile under Tcl 8.4 or 8.5 and load the extension under ...
    (comp.lang.tcl)
  • Re: convert tcl in a standalone application thanks to MinGw
    ... already many proposed solution, I didn't find the right solution. ... I found it cool to combine C and tcl. ... you only have to compile your c extension and any C compiler may ... You create an 'extension' coded in C/C++. ...
    (comp.lang.tcl)
  • Re: convert tcl in a standalone application thanks to MinGw
    ... I found it cool to combine C and tcl. ... You create an 'extension' coded in C/C++. ... Unfortunately Tclkit is not distributed in the form ... You don't need to compile the tclkit itself. ...
    (comp.lang.tcl)
  • Re: Tcl core wasnt compiled for multithreading
    ... Tcl core wasn't compiled for multithreading. ... In general for any extension author, ... can compile your extension with --enable-threads and then it ...
    (comp.lang.tcl)
  • Re: Goodbye TCL
    ... anyone that likes TCL and TK and wants to see ... support for the language increase rather then decrease and usage increase ... Unfortunately it is not the TCL core, it comes with restrictions, anf it ... "distribution of record" for what clearly many users want - an extension ...
    (comp.lang.tcl)