[Fwd: [Fwd: Dynamically loading vtk into Tcl/Tk]]

Matt Clarkson m.clarkson at boris.umds.ac.uk
Wed Mar 15 12:19:40 EST 2000


Ok I posted the message below previously:

This may be of interest to other people trying to load libraries
dynamically into wish.

So, thanks to Michael Halle, who managed to fix the
problem which occurs with Sun CC.

I modified the file tcl/vtktcl.c to have 
an extern C round each C function, and then compiled
it specifically with a C++ compiler (CC)
extern "C" {
	function()
}

previously, this file was being compiled with the
Sun C compiler (cc) and then linked with the C++
compiler (CC), resulting in incorrect name mangling.

The resulting file is attatched to this email.

Thanks to other people who replied.

Have fun,

Matt Clarkson


---------------START OF PREVIOUS
MESSAGE---------------------------------

Hi there David and the vtk list

        We have two versions of vtk, one compiled with Sun's CC,cc and
one with gnu g++/gcc.
I tried to create the dynamically loadable library, as suggested below.
In a nutshell, it works with the g++ version, but not with the CC
compiled
version?  The configuration is essentially the same, so, has
anyone else found this with a Sun CC compiled version?
Any other suggestions? I do need the Sun CC version to work.

Typically:

with the Sun CC version:

/projects/local/vtk/vtk2.4/tcl 68 %wish
% load ./vtktcl
couldn't load file "./vtktcl": ld.so.1: wish: fatal: relocation error:
file /projects/local/vtk/vtk2.4/lib/libVTKContribTcl.so: symbol cerr:
referenced symbol not found
% 


with the Gnu g++ version:

/projects/local/vtk/vtk2.4_gcc/tcl 36 %wish
% load ./vtktcl
% 

All the libraries are dynamic .so ones, and all the paths/ environements
seem OK. It really does seem to be a compiler problem.

Any help would be appreciated. Many thanks in advance.

---------------END OF PREVIOUS MESSAGE---------------------------------

> To fix the "cerr not defined" problem, you might want to try adding
> the "-lC" flag at the point where the contrib tcl library gets built.
> I'd suggest removing libVTKContribTcl.so, typing make all and
> redirecting the output into a file, then add -lC to the libraries by
> hand.  If it works (at least for contrib), then you could add it to
> the appropriate makefiles.
>
>
>                                                       --Mike

> I have a vague memory of succeeding in what you're trying to do, so
> keep it up.  Maybe also try linking in -lVTKContrib when
> libVTKContribTcl.so gets created.
> 
> Finally, I think the error you're getting is because C++ is mangling
> some of the method names that are actually C calls.  Somewhere, there
> might be a line like this missing or misplaced:
>
> extern "C" {
>  // something about Vtkcommontcl_Init here, or should be.
>
> }
-------------- next part --------------
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: vtktcl.c,v $
  Language:  C++
  Date:      $Date: 2000/02/04 17:09:29 $
  Version:   $Revision: 1.7 $


Copyright (c) 1993-2000 Ken Martin, Will Schroeder, Bill Lorensen 
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

 * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
   of any contributors may be used to endorse or promote products derived
   from this software without specific prior written permission.

 * Modified source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/


#include "tk.h"

extern "C" {
  Vtkcommontcl_Init(Tcl_Interp *interp);
}

#ifdef VTK_USE_GRAPHICS
extern "C" { 
  Vtkgraphicstcl_Init(Tcl_Interp *interp);
}

#ifdef VTK_USE_TKWIDGET
extern "C" { 
  Vtktkrenderwidget_Init(Tcl_Interp *interp);
}
#endif
#endif

#ifdef VTK_USE_IMAGING
extern "C" { 
  Vtkimagingtcl_Init(Tcl_Interp *interp);
}

#ifdef VTK_USE_TKWIDGET
extern "C" { 
  Vtktkimagewindowwidget_Init(Tcl_Interp *interp);
}
extern "C" { 
  Vtktkimageviewerwidget_Init(Tcl_Interp *interp);
}
#endif
#endif

#ifdef VTK_USE_PATENTED
extern "C" { 
  Vtkpatentedtcl_Init(Tcl_Interp *interp);
}
#endif

#ifdef VTK_USE_CONTRIB
extern "C" { 
  Vtkcontribtcl_Init(Tcl_Interp *interp);
}
#endif

#ifdef VTK_USE_LOCAL
extern "C" { 
  Vtklocaltcl_Init(Tcl_Interp *interp);
}

#endif

extern "C" {
  Vtktcl_Init(Tcl_Interp *interp);
}


int Vtktcl_Init(Tcl_Interp *interp)
{
  /* init the core vtk stuff */
  if (Vtkcommontcl_Init(interp) == TCL_ERROR) 
    {
    return TCL_ERROR;
    }
    
#ifdef VTK_USE_GRAPHICS
  if (Vtkgraphicstcl_Init(interp) == TCL_ERROR) 
    {
    return TCL_ERROR;
    }
#ifdef VTK_USE_TKWIDGET
  if (Vtktkrenderwidget_Init(interp) == TCL_ERROR) 
    {
    return TCL_ERROR;
    }
#endif
#endif

#ifdef VTK_USE_IMAGING
  if (Vtkimagingtcl_Init(interp) == TCL_ERROR) 
    {
    return TCL_ERROR;
    }
#ifdef VTK_USE_TKWIDGET
  if (Vtktkimagewindowwidget_Init(interp) == TCL_ERROR)
    {
    return TCL_ERROR;
    }
  if (Vtktkimageviewerwidget_Init(interp) == TCL_ERROR) 
    {
    return TCL_ERROR;
    }
#endif
#endif

#ifdef VTK_USE_PATENTED
  if (Vtkpatentedtcl_Init(interp) == TCL_ERROR) 
    {
    return TCL_ERROR;
    }
#endif

#ifdef VTK_USE_CONTRIB
  if (Vtkcontribtcl_Init(interp) == TCL_ERROR) 
    {
    return TCL_ERROR;
    }
#endif

#ifdef VTK_USE_LOCAL
  if (Vtklocaltcl_Init(interp) == TCL_ERROR) 
    {
    return TCL_ERROR;
    }
#endif

    return TCL_OK;
}

int Vtktcl_SafeInit(Tcl_Interp *interp)
{
  return Vtktcl_Init(interp);
}


More information about the vtkusers mailing list