Shamkumar Rajput
Shamkumar Rajput

Reputation: 166

How to load A.dll (Debug DLL) in Tcl Interpreter (8.5 Release Vesion)

How to load A.dll (Debug DLL) in Tcl Interpreter (8.5 Release Version)

=> I have created plugin A.dll(Debug DLL) for Tcl Interpreter.

=> I am able to load A.dll (Debug DLL) in Tcl Interpreter (8.5 Debug Version)

 I have used load {A.dll} 

=> Whenever I wanted to load A.dll (Debug Version) in Tcl Interpreter(8.5 Release Version)

 It gives an error => "Couldn't load dll"

=> Why did I want to load Debug DLL in Release version of Tcl interpreter? I wanted to put the breakpoint inside A.dll.

=> Is there any way do this? I am on windows platform.

=> Is there any flag I need to enable while building A.dll?

Upvotes: 0

Views: 348

Answers (1)

patthoyts
patthoyts

Reputation: 33193

There should be no problem loading an extension library build using the debug C runtime into a release version of the Tcl executable. As an example I've built a minimal Tcl extension using Visual Studio's compiler and loaded it into a release version of Tcl 8.6:

/*
 * cl -nologo -W3 -Od -MDd -Zi -D_DEBUG -DUSE_TCL_STUBS -I/opt/tcl/include tcl_demo.c 
 *    -Fe:demo.dll -link -dll -debug -libpath:c:\opt\tcl\lib tclstub86.lib
 */

#include <tcl.h>

static int DemoCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Tcl_SetObjResult(interp, Tcl_NewStringObj("demo", -1));
    return TCL_OK;
}

int DLLEXPORT Demo_Init(Tcl_Interp *interp)
{
    Tcl_InitStubs(interp, TCL_VERSION, 0);
    Tcl_CreateObjCommand(interp, "demo", DemoCmd, NULL, NULL);
    Tcl_PkgProvide(interp, "demo", "1.0");
    return TCL_OK;
}

This has been built using the command line given in the comment. You may need to change the path to the Tcl include and lib folders. This produces a debug dll (-MDd uses the debug C runtime, -Zi produces symbols, -Od disables optimizations, -D_DEBUG enables debug features in the runtime).

C:\Code\tcl>tclsh
% load demo.dll
% demo
demo
% exit

You can also build release DLLs that include symbol information by the way. cl -nologo -W3 -Ox -MD -Zi -DNDEBUG -DUSE_TCL_STUBS -I/opt/tcl/include tcl_demo.c -Fe:demo.dll -link -dll -debug -libpath:c:\opt\tcl\lib tclstub86.lib. Not much difference, we ask the compiler to issue symbols (-Zi) and the linker to generate the pdb file (-debug) but generate an optimized binary (-Ox) and define the release mode macro (-DNDEBUG).

Upvotes: 1

Related Questions