Re: Need help with loading .SO file




Shuri...@xxxxxxxxx wrote:
Michael Schlenker wrote:
ShurikAg@xxxxxxxxx schrieb:
Tobias Hippler wrote:
ShurikAg@xxxxxxxxx wrote:
There is Proc.cpp:
#include "tcl.h"

//#pragma comment(lib,"C:/TCL/lib/tcl84.lib")

int GetText(ClientData clientData,
Tcl_Interp *interp,
int argc, char *argv[]);

int Proc_Init(Tcl_Interp *interp)
{
if (Tcl_InitStubs(interp, "8.3", 0) == NULL) {
return TCL_ERROR;
}

Tcl_CreateCommand(interp, "gettext", GetText,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);

Tcl_PkgProvide(interp, "gettext", "1.1");


return TCL_OK;
}

int GetText(ClientData clientData, Tcl_Interp *interp, int argc, char
*argv[])
{

sprintf(interp->result, "%d", 25);
return TCL_OK;
}


Compiling: gcc -fPIC -c Proc.cpp
Linking: gcc -shared -o Proc.so Proc.o

Entering to TCL: wish8.3

Trying to load the Library: % load
/nfs/iil/disks/home05/aagulya/TCL/Proc.so

... and getting the error: couldn't find procedure Proc_Init

Where am I wrong????

Hi,

you have to add extern "C" in front of the definition of Proc_Init:

extern "C" int Proc_Init(Tcl_Interp *interp)
{
if (Tcl_InitStubs(interp, "8.3", 0) == NULL) {
return TCL_ERROR;
...
...
}

Otherwise the symbols of your *.so get mangled (c++ - style) and the
runtime loader can't find the symbol "Proc_Init".
BTW if you don't have to use C++, you can simply rename your file to
"Proc.c". This way the C compiler is used and no name mangling occurrs.

Cheers,
Tobi

Thanks, Tobi.

You are right.
But my main problem is compiling this the static TCL library.
If I'm trying to copile like this: gcc -fPIC -c Proc.cpp
the tcl loader screaming about unresolved simbles; as far as I
understand it happens because I did not compile my prog with out
libtk8.3.a.
How do I suppose to do it?
I think it somthing like: gcc -fPIC -l libtk8.3.a -c Proc.cpp
But it doesn't work...

Its the wrong lib. You initialize STUBS in your code, so link with the
stubs lib and define -DUSE_TCL_STUBS during compile. libtclstub8.3.a is
the lib in your case.

Michael

Is it durin the compiling or during linking?

Proc.cpp file:
#include "tcl.h"

//#pragma comment(lib,"C:/TCL/lib/tcl84.lib")

int GetObjText(ClientData clientData,
Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);

extern "C" int Proc_Init(Tcl_Interp *interp)
{
if (Tcl_InitStubs(interp, "8.4", 0) == NULL) {
return TCL_ERROR;
}

Tcl_CreateObjCommand(interp, "gettext", GetObjText,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);

Tcl_PkgProvide(interp, "gettext", "1.1");


return TCL_OK;
}

int GetObjText(ClientData clientData, Tcl_Interp *interp, int objc,
Tcl_Obj *CONST objv[])
{
Tcl_Obj *resultPtr;

resultPtr = Tcl_GetObjResult(interp);
Tcl_SetIntObj(resultPtr, 25);
return TCL_OK;
}

this is what I'm doing:
ismc01 [164] gcc -fPIC -c Proc.cpp

ismc01 [165] gcc -shared -L
/nfs/iil/itools/sun4m_solaris_2.6/pkgs/tcl-tk/8.3.2/lib/ -ltclstub8.3
-o Proc.so Proc.o

every thing compiles without problems.
Then, in "wish8.3":
% load /nfs/iil/disks/home05/aagulya/TCL/Proc.so
couldn't load file "/nfs/iil/disks/home05/aagulya/TCL/Proc.so":
ld.so.1: wish8.3: fatal: relocation error: file
/nfs/iil/disks/home05/aagulya/TCL/Proc.so: symbol __gxx_personality_v0:
referenced symbol not found

.



Relevant Pages

  • Re: C++/TCL Need Solution to Compile Error c2784
    ... Tcl_Interp *interp, ... int DisconnectObjCmd(ClientData clientData, ... Tcl_CreateObjCommand(interp, "Disconnect", DisconnectObjCmd, ...
    (comp.lang.tcl)
  • Re: Segmentation fault in internal Tcl function
    ... static int updateTclVariables ... Tcl_Preserveinterp); ... private clientdata structure and pass them to thread per-value instead of per- ... called by the above updateTclVariables and puts it into the QueueEvent. ...
    (comp.lang.tcl)
  • Re: Need help with loading .SO file
    ... int GetText(ClientData clientData, ... int Proc_Init(Tcl_Interp *interp) ... Tcl_CreateCommand(interp, "gettext", GetText, ... But my main problem is compiling this the static TCL library. ...
    (comp.lang.tcl)
  • Re: Need help with loading .SO file
    ... int GetText(ClientData clientData, ... int Proc_Init(Tcl_Interp *interp) ... Tcl_CreateCommand(interp, "gettext", GetText, ... But my main problem is compiling this the static TCL library. ...
    (comp.lang.tcl)
  • Re: Need help with loading .SO file
    ... int GetText(ClientData clientData, ... int Proc_Init(Tcl_Interp *interp) ... int GetText(ClientData clientData, Tcl_Interp *interp, int argc, char ... But my main problem is compiling this the static TCL library. ...
    (comp.lang.tcl)