[http://www.equi4.com/images/critcl-easier.png] ---- A shortcut for [CriTcl builds C extensions on-the-fly] The name stands for '''Compiled Runtime In Tcl'''. * The Critcl homepage is http://www.equi4.com/critcl * [Arjen Markus] is working on a Fortran extension - [Critcl goes Fortran] Tcl 2002 conference paper by Steve Landers and Jean-Claude Wippler is now at [http://www.digital-smarties.com/Tcl2002/critcl.pdf], with slides from [JCW]'s presentation at [http://www.equi4.com/docs/vancouver/pres2.htm]. Below are some simple how-to examples. ---- '''Using inlined C code''' * make sure you have a working gcc (or mingw) setup * get the critlib distribution and unpack [http://www.equi4.com/critlib/critlib.tar.gz] * create a test script called "three.tcl" with the following contents: lappend auto_path . package require critcl critcl::cproc triple {int i} int { return i * 3; /* this is C code */ } puts "three times 123 is [triple 123]" * run the above script (using tclsh, [tclkit], whatever), e.g. tclkit three.tcl * that's it - you should see the result of compiled C code * [SC] fixed typo in code above, it had critcl::ccode instead of critcl::cproc, ditto below ---- '''Building an extension for general use''' * get [Steve Landers]' CriTcl [Starkit] from [http://www.equi4.com/pub/sk/critcl.kit] and rename to "critcl" * note that you do not need to get critlib (but you do need a working gcc) * get a suitable copy of "tclkit" and make sure it works, see [http://www.equi4.com/starkit/37] * you can get on-line help by doing "tclkit critcl" * create a test script called "four.tcl" with the following contents: package provide four 1.0 package require critcl critcl::cproc quadruple {int i} int { return i * 4; /* this is C code */ } * you can now turn it into a shared library extension with one command: cd /path/where/four.tcl/lives/ tclkit /path/to/critcl -pkg four.tcl and the result is: Source: four.tcl Library: four.so Package: /path/where/four.tcl/lives/lib/four * to test it, you could use the following script: lappend auto_path lib package require four puts "four times 123 is [quadruple 123]" * note that critcl is no longer required when using this extension * the "four" extension is TIP55 compliant and can be used with any stub-enabled release of Tcl ---- '''Cross compiling using [Xmingwin]''' CriTcl supports cross compiling libraries and packages for Windows on Linux/Unix using the Xmingwin cross-compiler (based on mingw - http://www.mingw.org). * Once you are successful at [Xmingwin installation], you'll need to set your PATH to include the Xmingwin bin directory before using CriTcl. One convenient way of doing this is to create a script called ''cross'' (in /usr/local/bin or ~/bin). $ cat /usr/local/bin/cross PATH=/usr/local/Xmingwin/i386-mingw32msvc/bin:$PATH export PATH exec $@ * Then, you can compile using the usual CriTcl package (or library) building commansd $ cross critcl -pkg four.tcl Cross compiling for Windows using Xmingwin Source: four.tcl Library: four.dll Package: /path/to/four/lib/four * If CriTcl recognises a cross compile environment, it manipulates the tcl_platform array so that it matches that found on Windows 2000. Specifically, the following values are set tcl_platform(byteOrder) = littleEndian tcl_platform(machine) = intel tcl_platform(os) = Windows NT tcl_platform(osVersion) = 5.0 tcl_platform(platform) = windows tcl_platform(wordSize) = 4 * Critcl also provides the '''[[critcl::sharedlibext]]''' procedure, which returns the shared library extension for the target platform. If you plan on cross-compiling you should use this variable in your CriTcl scripts instead of '''[[info sharedlibextension]]''' (although overlaying the '''info sharedlibextension''' command will probably happen at some stage). * Intermediate files are stored in '''~/.critcl/Windows-x86''' irrespective of the platform on which cross compiling occurs For an example, download http://mini.net/sdarchive/critex.tar.gz, unload and change to the ex2/ directory. This contains a blowfish extension for Tcl. To build on Linux/Unix, run $ critcl -pkg blowfish Source: blowfish.tcl Library: blowfish.so Package: /path/to/ex2/lib/blowfish Then, to cross compile (via the above '''cross''' script) run $ cross critcl -pkg blowfish Cross compiling for Windows using Xmingwin Source: blowfish.tcl Library: blowfish.dll Package: /path/to/ex2/lib/blowfish If you look under ex2/lib/blowfish you'll see lib/blowfish lib/blowfish/critcl.tcl lib/blowfish/pkgIndex.tcl lib/blowfish/Windows-x86 lib/blowfish/Windows-x86/critcl.tcl lib/blowfish/Windows-x86/blowfish.dll lib/blowfish/Linux-x86 lib/blowfish/Linux-x86/critcl.tcl lib/blowfish/Linux-x86/blowfish.so The pkgIndex.tcl will autoload the correct binary for a particular platform. ---- ''Sep 2002'' - Critcl sources are now in CVS (pw empty, so no login needed): cvs -d :pserver:anonymous@equi4.com:/home/cvs -z3 co critcl To create a starkit from it, also do: ln -s critcl critcl.vfs sdx wrap critcl.kit -[jcw] ---- Discussion below moved from [Scripted Compiler] to the more natural place. [AM] Because of Critcl I am working on a package that abstracts the concept of a compiler and a linker away from the platform-dependencies. This way Critcl will be able to support "any" compiler/linker without the user (or the Critcl programmer) having to jump through hoops. [Vince] That sounds great! [Victor] Without linker ?? How then I use gcc produced *.o or archives ? That is Critcl libs should take this place. Are they encrypted ? And it is still a long way to have it accepted by many people. [NEM] There is [Babel], by Paul Duffin. However, like Feather, it may take a while to get hold of any code from Paul. ---- "How to use C and Tcl Together" [http://www.cuj.com/articles/2002/0212/0212toc.htm?topic=articles] presents Critcl [[CriTcl]] as a profoundly important innovation. ''[escargo] 11/11/2002:'' I got a 404 on this link. [IDG] Me too. The link is up and functional now - [AK]. ''[escargo] 12/5/2002:'' I see a table of contents, but no link to an article. Is it expected that the link above lead to the article itself? ---- Critcl makes a brief appearance in this [http://www-106.ibm.com/developerworks/linux/library/l-sc10.html] column on [XMingwin]. ---- [Critcl does C++] ---- [UKo] How can I inject code into the package initialisation section? This is necessary to build new canvas commands or new sound subcommands for [Snack]. [AM] There is a command ''cinit'' that allows you to do this.