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!

C & Tcl basics: how to build/compile 1

Status
Not open for further replies.

cuti

Programmer
Oct 2, 2003
5
VN
I appologize if I'm asking something obvious but...I need to add some C functions to my Tcl code and I have no programming experience so I realy need your advice.I'm supposed to use VC++ 6.0 and I would like to know if I have to build Tcl from source to be able to write extensions and second,how do I compile my extension in VC++.I have read a whole bunch of stuff about it but I'm still not able to figure out how to do it,step by step.I found something about building a project that uses external make file as well as compiling the C stuff as a .dll but I was not able to have any success.If someone would be so kind to explain how these things work in real life and for unexperienced programmers,I would really appreciate it.Thanks a lot!
 
Ouch. Inexperienced programmers should never be asked to write a C program. There're far too many pitfalls for the unwary.

Anyway, as to your first question: No, you don't need to compile Tcl from scratch just to compile your own extension. On the other hand, you will need to download the Tcl source, so that you have access to the Tcl header files that you'll need to include in your extension's source.

As for your extension itself, if you've got existing C/C++ code that you need to expose as Tcl commands that you can use in a script, get SWIG. SWIG is a tool that can automatically generate the wrapper code needed to access C/C++ functions from Tcl. Plus, it can generate wrapper code for several other scripting languages, include Perl, Python, and Ruby. In simple cases, you can just point SWIG at your library's header files, and it can do the rest. For more complex cases, you'll need to give SWIG a bit more direction, but it's still much simpler than writing the interface code yourself. You can find more information about SWIG at
Finally, if you need to write everything from scratch, including the Tcl interface code, you'll probably need a lot more help than I can offer in a forum like this. The best I can do is to point you to the Tcl'ers Wiki ( specifically at the page "Writing Extensions,"
Good luck! - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Ken,
Thanks a lot for your explanation.It was a big help.I have managed to write some C code.Now,I have a new problem -everything compiles just fine but linking is a problem.I get error LNK2001: unresolved external symbol _Tcl_Main.
I'm using VC++6.0
Do you have an idea what might be wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top