Dear all,
I am compiling a dynamic library of my own (testlib.so)
When I load it, it gives the following error
OSError: .//server//vtkpython//testlib.so: undefined symbol: _ZN26vtkImageConnectivityFilter3NewEv
It not gives any error in compilation. It started giving error (on load) with VTK. I included in compilation all the dynamic libraries of VTK but:
ldd testlib.so
linux-vdso.so.1 (0x00007fffb9d53000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f1cffd65000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1cffd42000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1cffd3c000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1cffb5a000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1cffa0b000)
libgomp.so.1 => /lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f1cff9c9000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1cff9ac000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1cff7ba000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1cffe35000)
Seems that no VTK included library.
Can anyone please help me?
Thanks,
LuĂs Gonçalves
I put:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);
Must I put something else? The error remains.
Code:
#include <vtkAppendPolyData.h>
#include <vtkNew.h>
#include <vtkImageConnectivityFilter.h>
#include <vtkPolyData.h>
#include <vtkUnsignedCharArray.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkPolygon.h>
#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkConnectedPointsFilter.h>
#include <vtkConnectivityFilter.h>
#include <vtkPointConnectivityFilter.h>
#include <vtkPolyDataConnectivityFilter.h>
#include <vtkVersion.h>
#include <vtkImageMapper3D.h>
#include <vtkImageStencil.h>
#include <vtkImageStencilData.h>
#include <vtkImageToImageStencil.h>
#include <vtkPolyDataToImageStencil.h>
#include <vtkImageProperty.h>
vtkNew<vtkImageConnectivityFilter> connectivity[4];
vtkSmartPointer<vtkImageData> image4 = vtkSmartPointer<vtkImageData>::New();
int i1;
image4->SetDimensions(dim);
image4->SetSpacing(scale1);
image4->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
memcpy(image4->GetScalarPointer(), image3, dim[0]*dim[1]*dim[2]);
#pragma omp parallel num_threads(4)
{
int nr=omp_get_thread_num();
float x1=(datax[nr*2]+datax[nr*2+1])/2.0f;
float y1=(datay[nr*2]+datay[nr*2+1])/2.0f;
float z1=(dataz[nr*2]+dataz[nr*2+1])/2.0f;
vtkPoints *seedPoints2 = vtkPoints::New();
seedPoints2->InsertNextPoint(x1,y1,z1);
vtkUnsignedCharArray *seedScalars2 = vtkUnsignedCharArray::New();
seedScalars2->InsertNextValue(255);
vtkPolyData *seedData2 = vtkPolyData::New();
seedData2->SetPoints(seedPoints2);
seedData2->GetPointData()->SetScalars(seedScalars2);
connectivity[nr]->SetInputData(image4);
connectivity[nr]->SetScalarRange(255, 255);
connectivity[nr]->SetSeedData(seedData2);
connectivity[nr]->Update();
}
Hello, Luis
_ZN26vtkImageConnectivityFilter3NewEv
is a mangled symbol of vtkImageConnectivityFilter::New()
. The class’ header’s documentation (https://vtk.org/doc/nightly/html/vtkImageConnectivityFilter_8h_source.html) tells its path in source directory is Imaging/Morphological
. So, I guess its implementation class module library is vtkImagingMorphological-<VTK version>.so/dll
. Hence you can try:
VTK_MODULE_INIT(vtkImagingMorphological);
Abstract classes implementation modules are loaded at runtime, much like plug-ins (more about this here: https://vtk.org/Wiki/VTK/Build_System_Migration#How_Implementation_Modules_Are_Initialized). This means that they are not linked to your program at build time, that is, they won’t show up in ldd
(Unix) or Dependency Walker (Windows).
I hope this helps.
regards,
Paulo
Thanks.
Now gives a different error on load:
OSError: .//server//vtkpython//testlib.so: undefined symbol: _Z42vtkImagingMorphological_AutoInit_Constructv
Hello,
Please, look at the dependency diagram of Imaging
: https://vtk.org/doc/nightly/html/dir_abb77a6a4baf09a5bbdcc1f44c51be6c.html . Maybe you need to add vtkImagingCore
and vtkImagingGeneral
to your module initializations as well. Sorry, trying to find the correct modules is a bit of trial-and-error. VTK is designed for software built with CMake, which adds these initializations automatically for resolution at compile time. Non-CMake users are left to find the correct modules to initialize.
take care,
Paulo
The follow variable is defined: /usr/local/lib (where is vtk)
LD_LIBRARY_PATH=/usr/local/lib/:/usr/local/cuda/lib64:
Which VTK version are you using?
I am using the last one 9.0.3.
Now error:
OSError: .//server//vtkpython//testlib.so: undefined symbol: _Z33vtkImagingCore_AutoInit_Constructv
with:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkImagingMorphological);
VTK_MODULE_INIT(vtkImagingCore);
VTK_MODULE_INIT(vtkImagingGeneral);
VTK_MODULE_INIT(vtkCommonCore);
VTK_MODULE_INIT(vtkCommonDataModel);
VTK_MODULE_INIT(vtkCommonTransforms);
VTK_MODULE_INIT(vtkFiltersGeneral);
VTK_MODULE_INIT(vtkFiltersModeling);
VTK_MODULE_INIT(vtkFiltersSources);
VTK_MODULE_INIT(vtkCommonMath);
VTK_MODULE_INIT(vtkFiltersCore);
VTK_MODULE_INIT(vtkFiltersExtraction);
Imaging/Core
depends on Common
. Since you already added vtkCommonCore
, I don’t know what might be missing. Maybe the order is important. Try placing the most basic ones first (e.g: vtkCommon*
before the others).
If you have exhausted your attempts, you can try adding the libraries manually to your linker list:
LIBS=-lvtkGUISupportQt$$_VTK_VERSION_SUFFIX \
-lvtkCommonCore$$_VTK_VERSION_SUFFIX \
-lvtkFiltersSources$$_VTK_VERSION_SUFFIX \
-lvtkRenderingCore$$_VTK_VERSION_SUFFIX \
-lvtkCommonExecutionModel$$_VTK_VERSION_SUFFIX \
-lvtkInteractionStyle$$_VTK_VERSION_SUFFIX \
-lvtkRenderingOpenGL2$$_VTK_VERSION_SUFFIX \
(...)
I do this in my project. It may be redundant, but it’s there just in case.
I am in Linux. My compiling line:
nvcc --gpu-architecture=sm_75 -O3 -Xcompiler -I/usr/local/include/vtk-9.0/ -Xcompiler @l3.txt -Xcompiler -fopenmp --shared -Xcompiler -fPIC -shared testlib.cu -o testlib.so
I added a file (l3.txt) with the following:
-L/usr/local/lib/
-lvtkChartsCore-9.0
-lvtkCommonColor-9.0
-lvtkCommonComputationalGeometry-9.0
-lvtkCommonCore-9.0
-lvtkCommonDataModel-9.0
-lvtkCommonExecutionModel-9.0
-lvtkCommonMath-9.0
-lvtkCommonMisc-9.0
-lvtkCommonSystem-9.0
-lvtkCommonTransforms-9.0
-lvtkDICOMParser-9.0
-lvtkDomainsChemistry-9.0
-lvtkDomainsChemistryOpenGL2-9.0
-lvtkdoubleconversion-9.0
-lvtkexodusII-9.0
-lvtkexpat-9.0
-lvtkFiltersAMR-9.0
-lvtkFiltersCore-9.0
-lvtkFiltersExtraction-9.0
-lvtkFiltersFlowPaths-9.0
-lvtkFiltersGeneral-9.0
-lvtkFiltersGeneric-9.0
…
…
I took out all AutoInit. I incrementally removed the lines in error (AutoInit). Until have none.
One question. Is this code correct?
vtkSmartPointer<vtkImageConnectivityFilter> connectivity[4];
for (i1=0;i1 <4 ;i1++)
connectivity[i1]= vtkSmartPointer<vtkImageConnectivityFilter>::New();
Error:
OSError: .//server//vtkpython//testlib.so: undefined symbol: _ZN26vtkImageConnectivityFilter3NewEv
With AutoInit. Error:
OSError: .//server//vtkpython//testlib.so: undefined symbol: _Z35vtkImagingCommon_AutoInit_Constructv
Using l3.txt with VTK static compilation. Same errors. VTK do not appears in “ldd”
-L/usr/local/lib/
-Wl,-Bstatic
-lvtkChartsCore-9.0
-lvtkCommonColor-9.0
-lvtkCommonComputationalGeometry-9.0
-lvtkCommonCore-9.0
…
…
-Wl,-Bdynamic
Solved. Linked with static VTK library. Without AutoInit. And the following error:
nvcc --gpu-architecture=sm_75 -O3 -Xcompiler -I/usr/local/include/vtk-9.0/ -Xlinker @l3.txt -Xcompiler -fopenmp --shared -Xcompiler -fPIC -shared testlib.cu -o testlib.so
Xlinker was before Xcompiler.
I don’t see any problems with that code.
Good to know. I don’t know that compiler you use (nvcc). On Unix, I use gcc. Figures why you’re limited to using static libraries to work around the issue.
nvcc is the compiler of CUDA from Nvidia. It strips the C++ code from CUDA. And calls g++ to compile the C++.
I did not research why static libraries work and dynamic not. I only tested.