Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2010-10-29
16:12 • Ticket [3097212fff] Linking extension with stubs status still Closed with 4 ... artifact: 35b825c54a user: ferrieux
15:54 • Ticket [3097212fff]: 4 changes artifact: 72ec0c55ad user: ferrieux
15:44 • Ticket [3097212fff]: 4 changes artifact: 0b52854de0 user: abhayh
2010-10-28
21:13 • Ticket [3097212fff]: 4 changes artifact: 8254eb42ed user: abhayh
20:32 • Ticket [3097212fff]: 4 changes artifact: c5e0068f45 user: dkf
19:48 • Ticket [3097212fff]: 6 changes artifact: 0c095cd881 user: ferrieux
19:14 • Ticket [3097212fff]: 4 changes artifact: be502eeb4c user: abhayh
19:08 • Ticket [3097212fff]: 4 changes artifact: 7de72fc375 user: ferrieux
18:58 • Ticket [3097212fff]: 4 changes artifact: d8d13f0dd5 user: abhayh
18:53 • Closed ticket [3097212fff]. artifact: f525874934 user: ferrieux
18:53 • Ticket [3097212fff]: 4 changes artifact: 58390aa3d1 user: ferrieux
09:16 • New ticket [3097212fff]. artifact: 286016c5e1 user: abhayh

Linking extension with stubs

Closed / Invalid3097212fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-10-28 09:16:28
Hi everyone. I am using MS VS 2005 to write a simple TCL extension. Below is my code.

#include<tcl.h>
#include<iostream>
using namespace std;

int Add_Nums (ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv);
                       //ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv)


int DLLEXPORT
Add_Init(Tcl_Interp *interp)
{
   
    if(Tcl_InitStubs(interp,"8.4",0)==NULL){
        return TCL_ERROR;
    }
    if (Tcl_PkgProvide(interp, "add", "1.1") == TCL_ERROR) {
         return TCL_ERROR;
     }
    Tcl_Command Tcl_CreateObjCommand(interp,"add",Add_Nums,NULL,NULL);
    return TCL_OK;

}


int Add_Nums (ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv)    
{
    int adding(int no1,int no2);
    return TCL_OK;
}

int adding(int no1,int no2)
{
   
    int sum =0;
    cout<<"Enter the two numbers:"<<endl;
    cin>>no1>>no2;
   
    cout<<"Sum is "<<no1+no2<<endl;
    return(sum);
} 

When i build this , its giving me " Too many Initiallizers " pointing at Tcl_CreateObjCommand() line.

How do i resolve this?

Thanks
ferrieuxplain2010-10-28 18:53:38
That's a C typo. You don't want "Tcl_Command" just before the call to Tcl_CreateObjCommand.
Before submitting a bug report, try identifying the failing part. A compile error is hardly the Tcl library's responsibility.
ferrieux Closed ticket [3097212fff]. [History diff]2010-10-28 18:53:39
abhayhplain2010-10-28 18:58:14
Sorry about the typo.But in my actual it's Tcl_CreateObjCommand(), i have rechecked it. If this is not the right place to post the problem, can you please link me to the proper one & close this thread. 

Thanks
ferrieuxplain2010-10-28 19:08:58
Then paste your original !
abhayhplain2010-10-28 19:14:10
#include<tcl.h>
#include<iostream>
using namespace std;

int Add_Nums (ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv);
              //ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv)
int DLLEXPORT
Add_Init(Tcl_Interp *interp)
{

     #ifdef USE_TCL_STUBS
         Tcl_InitStubs(interp, "8.4", 0);
     #endif 
   
if (Tcl_PkgProvide(interp, "8.4", "1.1") == TCL_ERROR) {
         return TCL_ERROR;
 }
     Tcl_CreateObjCommand(interp,"add",Add_Nums,NULL,NULL);
     return TCL_OK;
 
}


int Add_Nums (ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv)
{
int adding(int no1,int no2);
    return TCL_OK;
}

int adding(int no1,int no2)
{

int sum =0;
cout<<"Enter the two numbers:"<<endl;
cin>>no1>>no2;

cout<<"Sum is "<<no1+no2<<endl;
return(sum);
 } 

Well, it's now showing me few linker errors.  I tried to debug it , but couldn't find a way.  It's getting compiled but has few unresolved symbol issues. 

These are the errors.

1> : error LNK2001: unresolved external symbol _tclStubsPtr
1> : error LNK2019: unresolved external symbol _Tcl_InitStubs referenced in function "int __cdecl Add_Init(struct Tcl_Interp *)" (?Add_Init@@YAHPAUTcl_Interp@@@Z)
1> : fatal error LNK1120: 2 unresolved externals
1> - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
ferrieuxplain2010-10-28 19:48:38
Changing the title, and the assignee, accordingly.
dkfplain2010-10-28 20:32:37
Solution part #1: You need to link with the tclstub library.
Solution part #2: The Add_Init function needs to have 'extern "C"' linkage or [load] will never be able to do anything with the lib.
Solution part #3: Tcl_PkgProvide's second argument needs to be the package name (e.g., "add" in this case).
abhayhplain2010-10-28 21:13:55
>>Solution part #2: The Add_Init function needs to have 'extern "C"' linkage
or [load] will never be able to do anything with the lib.
Solution part #3: Tcl_PkgProvide's second argument needs to be the package
name (e.g., "add" in this case).

I edited the code as above. 

#include<tcl.h>
#include<iostream>
using namespace std;

#ifndef STATIC_BUILD
#if defined(_MSC_VER)
#   define EXPORT(a,b) __declspec(dllexport) a b
#   define DllEntryPoint DllMain
#else
#   if defined(__BORLANDC__)
#       define EXPORT(a,b) a _export b
#   else
#       define EXPORT(a,b) a b
#   endif
#endif
#endif



int Add_Nums (ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv);
              //ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv)
int DLLEXPORT
extern "C" int Add_Init(Tcl_Interp *interp)
{

     #ifdef USE_TCL_STUBS
         Tcl_InitStubs(interp, "8.4", 0);
     #endif 
   
if (Tcl_PkgProvide(interp, "add", "1.1") == TCL_ERROR) {
         return TCL_ERROR;
 }
     Tcl_CreateObjCommand(interp,"add",Add_Nums,NULL,NULL);
     return TCL_OK;
 
}


int Add_Nums (ClientData clientData, Tcl_Interp *interp, int objc, struct Tcl_Obj * CONST * objv)
{
int adding(int no1,int no2);
    return TCL_OK;
}

int adding(int no1,int no2)
{

int sum =0;
cout<<"Enter the two numbers:"<<endl;
cin>>no1>>no2;

cout<<"Sum is "<<no1+no2<<endl;
return(sum);
 } 

>>Solution part #1: You need to link with the tclstub library.

How do i link with tclstub library?I have added tclstub84.lib in the "Linker"> Additioinal Library Dependencies.Is this the right way?


As of now ,I am getting the following error. 

1> error LNK2001: unresolved external symbol _tclStubsPtr
1> error LNK2019: unresolved external symbol _Tcl_InitStubs referenced in function _Add_Init
1> fatal error LNK1120: 2 unresolved externals
abhayhplain2010-10-29 15:44:58
I am able to resolve the issue. Thanks a lot :)

Now i'm having issues loading the dll.

% load Name_of_Dll_file.dll Pkgname gives me "Cannot find proc Name_of_Dll_file_init ..

I have few querries.
1. Should the Dll name & the Cpp source code name should be the same?
2.If my dll name is mydll.dll , then the name of  init function should be mydll_init , is it ?
3.What should be the package name?
ferrieuxplain2010-10-29 15:54:56
Maybe it 's a bit late to say this ... but this discussion doesn't quite belong there.
Next time, use the comp.lang.tcl newsgroup, where you'll reach a larger audience both of experts and followers.
ferrieuxplain2010-10-29 16:12:22
allow_comments - 1
Log in (anonymous is fine) to add a comment.