# Problem in Dynamic Library

**URL:** https://discourse.vtk.org/t/problem-in-dynamic-library/6365
**Category:** Support
**Created:** [August 12, 2021, 10:25pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365 "2021-08-12T22:25:24Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 12, 2021, 10:25pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/1 "2021-08-12T22:25:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 8:24am UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/2 "2021-08-13T08:24:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 8:37am UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/3 "2021-08-13T08:37:35Z")

</div>

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();

  }
```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 13, 2021, 1:50pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/4 "2021-08-13T13:50:19Z")

</div>

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](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:

```cpp
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](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

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 1:58pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/5 "2021-08-13T13:58:54Z")

</div>

Thanks.  
Now gives a different error on load:

OSError: .//server//vtkpython//testlib.so: undefined symbol: \_Z42vtkImagingMorphological\_AutoInit\_Constructv

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 13, 2021, 2:04pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/6 "2021-08-13T14:04:43Z")

</div>

Hello,

Please, look at the dependency diagram of `Imaging`: [https://vtk.org/doc/nightly/html/dir\_abb77a6a4baf09a5bbdcc1f44c51be6c.html](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

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 2:04pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/7 "2021-08-13T14:04:43Z")

</div>

The follow variable is defined: /usr/local/lib (where is vtk)  
LD\_LIBRARY\_PATH=/usr/local/lib/:/usr/local/cuda/lib64:

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 13, 2021, 2:10pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/8 "2021-08-13T14:10:21Z")

</div>

Which VTK version are you using?

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 2:21pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/9 "2021-08-13T14:21:53Z")

</div>

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);

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 13, 2021, 2:29pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/10 "2021-08-13T14:29:28Z")

</div>

`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).

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 13, 2021, 2:41pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/11 "2021-08-13T14:41:37Z")

</div>

If you have exhausted your attempts, you can try adding the libraries manually to your linker list:

```bash
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.

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 2:48pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/12 "2021-08-13T14:48:26Z")

</div>

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  
…  
…

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 4:18pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/13 "2021-08-13T16:18:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 4:37pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/14 "2021-08-13T16:37:26Z")

</div>

With AutoInit. Error:

OSError: .//server//vtkpython//testlib.so: undefined symbol: \_Z35vtkImagingCommon\_AutoInit\_Constructv

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 5:48pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/15 "2021-08-13T17:48:21Z")

</div>

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

* * *

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 8:10pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/16 "2021-08-13T20:10:22Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 13, 2021, 9:34pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/17 "2021-08-13T21:34:33Z")

</div>

I don’t see any problems with that code.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 13, 2021, 9:37pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/18 "2021-08-13T21:37:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 10:02pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/19 "2021-08-13T22:02:37Z")

</div>

nvcc is the compiler of CUDA from Nvidia. It strips the C++ code from CUDA. And calls g++ to compile the C++.

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [August 13, 2021, 10:09pm UTC](https://discourse.vtk.org/t/problem-in-dynamic-library/6365/20 "2021-08-13T22:09:13Z")

</div>

I did not research why static libraries work and dynamic not. I only tested.

[Next page](https://discourse.vtk.org/t/problem-in-dynamic-library/6365.md?page=2)
