Embedding Tcl in C Program

I am trying to create a simple C ++ console application that calls nagelfar syntax check on a script. I followed the directions here: http://wiki.tcl.tk/19919 , adding tclstub85.lib to my input, adding the tcl lib directory to my additional libraries and adding my header directory. Communication failure with:

 main.obj : error LNK2001: unresolved external symbol _tclStubsPtr 

This is my command line for the link:

 /OUT:"C:\Users\######\Documents\Visual Studio 2005\Projects\Nagelfar\Release\Nagelfar.exe" /NOLOGO /LIBPATH:"C:\Tcl\lib" /MANIFEST /MANIFESTFILE:"Release\Nagelfar.exe.intermediate.manifest" /DEBUG /PDB:"c:\users\######\documents\visual studio 2005\projects\nagelfar\release\Nagelfar.pdb" /OPT:REF /OPT:ICF /LTCG /MACHINE:X86 /ERRORREPORT:PROMPT C:\Tcl\lib\tclstub85.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 

This is the complete source code that I can compile and execute perfectly on Linux using g ++:

 #include <stdlib.h> #include <stdio.h> #include <tcl.h> #include <string.h> Tcl_Interp * tcl_interp ; char fileToCheck[] = "test.tcl"; char dbFile[] = "syntaxdb.tcl"; int main () { int code, argc; const char **argv; char command[1024]; char *results = NULL; tcl_interp = Tcl_CreateInterp(); Tcl_SetVar2(tcl_interp, "::Nagelfar", "embedded", "1", 0); code = Tcl_EvalFile(tcl_interp, "nagelfar.tcl"); Tcl_LinkVar(tcl_interp, "::Nagelfar(chkResult)", (char *)&results, TCL_LINK_STRING); sprintf(command, "synCheck %s %s", fileToCheck, dbFile); code = Tcl_Eval(tcl_interp, command); printf("Raw Result: \r\n %s\r\n", results); code = Tcl_SplitList(tcl_interp, results, &argc, &argv); { int i; for (i = 0; i < argc; ++i) { printf("%d/%d: %s\r\n", i+1, argc, argv[i]); } } Tcl_Free(results); return 0; } 

Solved my own problem: I had x64 ActiveTcl, but a 32-bit project was linked. Using x86 ActiveTcl distribution fixed my problems.

+4
source share
2 answers

Solved my own problem: I had x64 ActiveTcl, but a 32-bit project was linked. Using x86 ActiveTcl distribution fixed my problems.

+1
source

Your error message tells us that you are expecting a stub table (Tcl goes by the name tclStubPtr when all macros are extended), which, in turn, indicates that the preprocessor character USE_TCL_STUBS . This symbol is intended for use when you are writing a library that provides additional Tcl functions. However, in the case when you write the main application that calls functions in the Tcl library - for example, "run this code" - you cannot (easily) use the stub mechanism, since you will need a stub table before Tcl is able to provide it to you.

The fix is โ€‹โ€‹to not define USE_TCL_STUBS and reference the main Tcl library (possibly C:\Tcl\lib\tcl85.dll on your system) instead of tclstub85.lib . (I donโ€™t know enough about how to configure Visual Studio to say what details of this configuration are.)


You should also add this line to your code before calling Tcl_CreateInterp() :

 Tcl_FindExecutable(NULL); 

This call is used to allow the Tcl library core to initialize itself by doing small things, such as getting the memory manager and the file system interface level.

+1
source

Source: https://habr.com/ru/post/1446290/


All Articles