pcl icon indicating copy to clipboard operation
pcl copied to clipboard

Allow hidden visibility default on gcc/clang

Open mvieth opened this issue 1 year ago • 3 comments

Can be enabled/disabled with the CMake option PCL_SYMBOL_VISIBILITY_HIDDEN. The main benefits are reduced library size and reduced risk of certain bugs. Some sources also claim that it can increase execution speed under certain conditions, but so far I did not test whether this is the case for PCL. This is feature is still somewhat experimental (although I did a lot of testing), so for anyone reading this who got a linker error when this is enabled: please open an issue, it may be that PCL_EXPORTS is missing somewhere.

Range image

For gcc, I could only get it to work with the whole RangeImage class marked as PCL_EXPORTS (i.e. __attribute__ ((visibility ("default")))), otherwise I get the linking error undefined reference to vtable RangeImage. For MSVC on the other hand, marking the whole class as PCL_EXPORTS (i.e. __declspec(dllexport)) seems to be problematic because when including range_image.h in another PCL module, RangeImage is also marked as dllexport so the compiler seems to expect a definition of the static members (lookup tables) in that module as well. In the future, it might be a good idea to move away from the static class member lookup tables, and perhaps use static local variables instead like in RGB2sRGB_LUT).

Supervoxel clustering

Moved the specializations of getPoint to supervoxel_clustering.h, using traits::HasColor. This was necessary to resolve some interdependencies between SupervoxelClustering, OctreePointCloudAdjacencyContainer, and `OctreePointCloudAdjacency

Further changes

  • removed PCL_EXPORTS on TransformationEstimationSVD again. I added it in a previous PR but noticed now that it was not necessary and caused warnings on MSVC.

Library size

in kilobytes MinSizeRel, hidden symbols MinSizeRel, hidden symbols off Release, hidden symbols Release, hidden symbols off
common 726 839 825 879
features 43023 49729 51947 57824
filters 8708 10326 10013 11194
io_ply 324 412 401 467
io 2454 3272 2985 3587
kdtree 1199 1565 1453 1754
keypoints 1674 2032 2040 2337
ml 125 146 188 196
octree 2593 2818 3252 3371
outofcore 81 85 97 101
people 22 22 29 29
recognition 5455 6821 6642 7592
registration 2108 2793 2428 2829
sample_consensus 13392 14776 16101 17036
search 2059 2501 2463 2850
segmentation 12893 16671 15067 18132
stereo 241 258 302 306
surface 6304 7174 8178 8747
tracking 3903 4578 4814 5378
visualization 1294 1648 1601 1865

Built with GCC 13.2. All CMake options except CMAKE_BUILD_TYPE and PCL_SYMBOL_VISIBILITY_HIDDEN are the default ones

mvieth avatar Aug 02 '23 09:08 mvieth

This would close #1913 FYI.

larshg avatar Dec 04 '23 07:12 larshg

Range image

You should move the key function (in this case virtual destructor) into a CPP file. https://gcc.gnu.org/wiki/VerboseDiagnostics#missing_vtable

Osyotr avatar Aug 03 '24 15:08 Osyotr

Range image

You should move the key function (in this case virtual destructor) into a CPP file. https://gcc.gnu.org/wiki/VerboseDiagnostics#missing_vtable

Thanks for the suggestion, that seems to work. Then let's go with that solution since it does not require an if-else based on the compiler.

mvieth avatar Aug 12 '24 09:08 mvieth