Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

steps to call c function from tcl? 1

Status
Not open for further replies.

baiyan

Programmer
Mar 4, 2002
2
US
I have a "test.c" which contains several functions (func1(), func2(), and func3()). I want to call these functions from tcl. How? Should I set any environment variables to make it work?

For I am quite new to TCL, a step-by-step instruction is greatly appreciated.

 
Tcl was designed to make it easy to create new Tcl commands using C code. Ironically, this has become one of the most poorly documented areas of Tcl programming, especially as new features have been added to the language.

I'll point you to the Tcl'ers Wiki ( specifically the page "How to use C functions from Tcl" at for a catch-all collection of pointers to information. Of the resources listed there, I think that you'll find the chapter from Brent Welch's book, Practical Programming in Tcl and Tk, 3rd ed., to be a good starting point. And Brent has generously made that chapter available on the web in PDF format at
Having said all that, since you've got an existing C library, I highly recommend that you check out SWIG, SWIG is a tool that can automatically generate the wrapper code needed to expose C/C++ functions as Tcl commands. It also generates wrapper code for Perl, Python, and a couple other scripting languages. Although you can get pretty sophisticated in customizing the wrapper generation, you can often get by with pointing SWIG at your library's header files and letting it do everything else. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top