Prevent symbols from being only local to the library?

I have been trying to link a code to vtk using gcc-11.2.0.

The link fails with

/usr/bin/ld: /…/vtk4ctk-8.1.0-sersh/lib/libvtkCommonExecutionModel-8.1.so.1: undefined reference to `vtkCollectionIterator::GoToFirstItem()’

but I see that in vtkCommonCore, which is present on the link line (see attached build log), is installed. However, nm shows

$ nm -CB libvtkCommonCore-8.1.so | grep GoToFirstItem
00000000000e4b10 t vtkCollectionIterator::GoToFirstItem()
00000000001b3f30 t vtkInformationIterator::GoToFirstItem()
0000000000063ab0 t vtkInformationIterator::GoToFirstItem() [clone .cold]

that this symbol, while present, is local to the library. Hence, the link fails.

This is not a problem with gcc-8.3.0 on this machine or gcc-9.4.0 on a different machine.

This is a problem with gcc-10.3.0, gcc-11.2.0, which it seems I need to use to get the C++ features that I want.

Same problem occurs for vtk-8.2.0.

How do I make these symbols not local to the library?

Thx…John Cary

I see now that “-fvisibility=hidden” is being added as a compilation flag. Any idea where this comes from?

VTK sets it itself. However, this does work on GCC 11 in CI. Though I see that you’re talking about VTK 8.

VTK 8.1 is really out-of-date and unsupported. I suspect this is something that got fixed in the new module system.

8.2.0 has the same problem. I fix this by, after configuring, running

find . -name flags.make -exec sed -i -e ‘s/-fvisibility=hidden//g’ ‘{}’ ;

Where in vtk does -fvisibility=hidden get added? (Then I can just patch it.)

There’s a variable CMAKE_CXX_VISIBILITY_PRESET that gets set somewhere in 8.2 (probably top-level CMakeLists.txt. The CMAKE_C_VISIBILITY_PRESET variable also needs cleared. You can set it to default instead of hidden.