From c712a446d39304a25f11128699e2223fffb20ac5 Mon Sep 17 00:00:00 2001 From: Markus Vieth Date: Wed, 2 Aug 2023 11:47:19 +0200 Subject: [PATCH 1/4] Test hidden visibility default on gcc --- cmake/pcl_options.cmake | 8 ++++ common/include/pcl/exceptions.h | 23 ++++----- common/include/pcl/pcl_exports.h | 8 +++- common/include/pcl/pcl_macros.h | 6 ++- common/include/pcl/range_image/range_image.h | 4 ++ filters/src/convolution.cpp | 12 ----- gpu/containers/src/initialization.cpp | 2 + pcl_config.h.in | 3 +- .../transformation_estimation_svd.h | 2 +- .../impl/crf_normal_segmentation.hpp | 2 +- .../impl/supervoxel_clustering.hpp | 48 +------------------ .../pcl/segmentation/supervoxel_clustering.h | 22 +++++++++ segmentation/src/supervoxel_clustering.cpp | 33 ++----------- 13 files changed, 69 insertions(+), 104 deletions(-) diff --git a/cmake/pcl_options.cmake b/cmake/pcl_options.cmake index 6fa8fdd359f..e5b968634f2 100644 --- a/cmake/pcl_options.cmake +++ b/cmake/pcl_options.cmake @@ -122,3 +122,11 @@ option(PCL_DISABLE_GPU_TESTS "Disable running GPU tests. If disabled, tests will # Set whether visualizations tests should be run # (Used to prevent visualizations tests from executing in CI where visualization is unavailable) option(PCL_DISABLE_VISUALIZATION_TESTS "Disable running visualizations tests. If disabled, tests will still be built." OFF) + +# This leads to smaller libraries, possibly faster code, and fixes some bugs. See https://gcc.gnu.org/wiki/Visibility +option(PCL_SYMBOL_VISIBILITY_HIDDEN "Hide all binary symbols by default, export only those explicitly marked (gcc and clang only). Experimental!" ON) +mark_as_advanced(PCL_SYMBOL_VISIBILITY_HIDDEN) +if(PCL_SYMBOL_VISIBILITY_HIDDEN) + set(CMAKE_CXX_VISIBILITY_PRESET hidden) + set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) +endif() diff --git a/common/include/pcl/exceptions.h b/common/include/pcl/exceptions.h index 3c1a3d1838c..5adfccf7585 100644 --- a/common/include/pcl/exceptions.h +++ b/common/include/pcl/exceptions.h @@ -40,6 +40,7 @@ #include #include #include +#include // for PCL_EXPORTS /** PCL_THROW_EXCEPTION a helper macro to be used for throwing exceptions. * This is an example on how to use: @@ -62,7 +63,7 @@ namespace pcl * \brief A base class for all pcl exceptions which inherits from std::runtime_error * \author Eitan Marder-Eppstein, Suat Gedikli, Nizar Sallem */ - class PCLException : public std::runtime_error + class PCL_EXPORTS PCLException : public std::runtime_error { public: @@ -134,7 +135,7 @@ namespace pcl /** \class InvalidConversionException * \brief An exception that is thrown when a PCLPointCloud2 message cannot be converted into a PCL type */ - class InvalidConversionException : public PCLException + class PCL_EXPORTS InvalidConversionException : public PCLException { public: @@ -148,7 +149,7 @@ namespace pcl /** \class IsNotDenseException * \brief An exception that is thrown when a PointCloud is not dense but is attempted to be used as dense */ - class IsNotDenseException : public PCLException + class PCL_EXPORTS IsNotDenseException : public PCLException { public: @@ -163,7 +164,7 @@ namespace pcl * \brief An exception that is thrown when a sample consensus model doesn't * have the correct number of samples defined in model_types.h */ - class InvalidSACModelTypeException : public PCLException + class PCL_EXPORTS InvalidSACModelTypeException : public PCLException { public: @@ -177,7 +178,7 @@ namespace pcl /** \class IOException * \brief An exception that is thrown during an IO error (typical read/write errors) */ - class IOException : public PCLException + class PCL_EXPORTS IOException : public PCLException { public: @@ -192,7 +193,7 @@ namespace pcl * \brief An exception thrown when init can not be performed should be used in all the * PCLBase class inheritants. */ - class InitFailedException : public PCLException + class PCL_EXPORTS InitFailedException : public PCLException { public: InitFailedException (const std::string& error_description = "", @@ -206,7 +207,7 @@ namespace pcl * \brief An exception that is thrown when an organized point cloud is needed * but not provided. */ - class UnorganizedPointCloudException : public PCLException + class PCL_EXPORTS UnorganizedPointCloudException : public PCLException { public: @@ -220,7 +221,7 @@ namespace pcl /** \class KernelWidthTooSmallException * \brief An exception that is thrown when the kernel size is too small */ - class KernelWidthTooSmallException : public PCLException + class PCL_EXPORTS KernelWidthTooSmallException : public PCLException { public: @@ -231,7 +232,7 @@ namespace pcl : pcl::PCLException (error_description, file_name, function_name, line_number) { } } ; - class UnhandledPointTypeException : public PCLException + class PCL_EXPORTS UnhandledPointTypeException : public PCLException { public: UnhandledPointTypeException (const std::string& error_description, @@ -241,7 +242,7 @@ namespace pcl : pcl::PCLException (error_description, file_name, function_name, line_number) { } }; - class ComputeFailedException : public PCLException + class PCL_EXPORTS ComputeFailedException : public PCLException { public: ComputeFailedException (const std::string& error_description, @@ -254,7 +255,7 @@ namespace pcl /** \class BadArgumentException * \brief An exception that is thrown when the arguments number or type is wrong/unhandled. */ - class BadArgumentException : public PCLException + class PCL_EXPORTS BadArgumentException : public PCLException { public: BadArgumentException (const std::string& error_description, diff --git a/common/include/pcl/pcl_exports.h b/common/include/pcl/pcl_exports.h index ef71bddadd8..f386303bc46 100644 --- a/common/include/pcl/pcl_exports.h +++ b/common/include/pcl/pcl_exports.h @@ -34,6 +34,8 @@ #pragma once +#include // for PCL_SYMBOL_VISIBILITY_HIDDEN + // This header is created to include to NVCC compiled sources. // Header 'pcl_macros' is not suitable since it includes , // which can't be eaten by nvcc (it's too weak) @@ -45,5 +47,9 @@ #define PCL_EXPORTS #endif #else - #define PCL_EXPORTS + #ifdef PCL_SYMBOL_VISIBILITY_HIDDEN + #define PCL_EXPORTS __attribute__ ((visibility ("default"))) + #else + #define PCL_EXPORTS + #endif #endif diff --git a/common/include/pcl/pcl_macros.h b/common/include/pcl/pcl_macros.h index 074b11149ed..0e2740965ee 100644 --- a/common/include/pcl/pcl_macros.h +++ b/common/include/pcl/pcl_macros.h @@ -323,7 +323,11 @@ pcl_round (float number) #define PCL_EXPORTS #endif #else - #define PCL_EXPORTS + #ifdef PCL_SYMBOL_VISIBILITY_HIDDEN + #define PCL_EXPORTS __attribute__ ((visibility ("default"))) + #else + #define PCL_EXPORTS + #endif #endif #if defined WIN32 || defined _WIN32 diff --git a/common/include/pcl/range_image/range_image.h b/common/include/pcl/range_image/range_image.h index 051979fe91f..92cabf613e1 100644 --- a/common/include/pcl/range_image/range_image.h +++ b/common/include/pcl/range_image/range_image.h @@ -51,7 +51,11 @@ namespace pcl * \author Bastian Steder * \ingroup range_image */ +#if defined _WIN32 || defined WINCE || defined __MINGW32__ class RangeImage : public pcl::PointCloud +#else + class PCL_EXPORTS RangeImage : public pcl::PointCloud +#endif { public: // =====TYPEDEFS===== diff --git a/filters/src/convolution.cpp b/filters/src/convolution.cpp index 7d35a463a0c..41ffd02be9c 100644 --- a/filters/src/convolution.cpp +++ b/filters/src/convolution.cpp @@ -189,17 +189,5 @@ Convolution::convolveOneColDense(int i, int j) result.b = static_cast(b); return (result); } - -#ifndef PCL_NO_PRECOMPILE -#include -#include - -PCL_INSTANTIATE_PRODUCT( - Convolution, ((pcl::RGB))((pcl::RGB))) - -PCL_INSTANTIATE_PRODUCT( - Convolution, ((pcl::PointXYZRGB))((pcl::PointXYZRGB))) -#endif // PCL_NO_PRECOMPILE - } // namespace filters } // namespace pcl diff --git a/gpu/containers/src/initialization.cpp b/gpu/containers/src/initialization.cpp index 8bcc642884b..dbd4cadf88c 100644 --- a/gpu/containers/src/initialization.cpp +++ b/gpu/containers/src/initialization.cpp @@ -42,7 +42,9 @@ #include // replace c-style array with std::array #include +#if !defined(HAVE_CUDA) #define HAVE_CUDA +#endif //#include #if !defined(HAVE_CUDA) diff --git a/pcl_config.h.in b/pcl_config.h.in index 3277fa77b05..33b808cf567 100644 --- a/pcl_config.h.in +++ b/pcl_config.h.in @@ -3,11 +3,12 @@ // Ensure the compiler is meeting the minimum C++ standard // MSVC is not checked via __cplusplus due to // https://developercommunity.visualstudio.com/content/problem/120156/-cplusplus-macro-still-defined-as-pre-c11-value.html -#if (!defined(_MSC_VER) && __cplusplus < 201402L) || (defined(_MSC_VER) && _MSC_VER < 1900) +#if defined(__cplusplus) && ((!defined(_MSC_VER) && __cplusplus < 201402L) || (defined(_MSC_VER) && _MSC_VER < 1900)) #error PCL requires C++14 or above #endif #define BUILD_@CMAKE_BUILD_TYPE@ +#cmakedefine PCL_SYMBOL_VISIBILITY_HIDDEN /* PCL version information */ #define PCL_MAJOR_VERSION ${PCL_VERSION_MAJOR} #define PCL_MINOR_VERSION ${PCL_VERSION_MINOR} diff --git a/registration/include/pcl/registration/transformation_estimation_svd.h b/registration/include/pcl/registration/transformation_estimation_svd.h index 60c960788bd..f9c56ea59a2 100644 --- a/registration/include/pcl/registration/transformation_estimation_svd.h +++ b/registration/include/pcl/registration/transformation_estimation_svd.h @@ -55,7 +55,7 @@ namespace registration { * \ingroup registration */ template -class PCL_EXPORTS TransformationEstimationSVD +class TransformationEstimationSVD : public TransformationEstimation { public: using Ptr = shared_ptr>; diff --git a/segmentation/include/pcl/segmentation/impl/crf_normal_segmentation.hpp b/segmentation/include/pcl/segmentation/impl/crf_normal_segmentation.hpp index cf00fa56a84..01b9dba9a91 100644 --- a/segmentation/include/pcl/segmentation/impl/crf_normal_segmentation.hpp +++ b/segmentation/include/pcl/segmentation/impl/crf_normal_segmentation.hpp @@ -71,6 +71,6 @@ pcl::CrfNormalSegmentation::segmentPoints () { } -#define PCL_INSTANTIATE_CrfNormalSegmentation(T) template class pcl::CrfNormalSegmentation; +#define PCL_INSTANTIATE_CrfNormalSegmentation(T) template class PCL_EXPORTS pcl::CrfNormalSegmentation; #endif // PCL_CRF_NORMAL_SEGMENTATION_HPP_ diff --git a/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp b/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp index 9d627c600ff..81e18855189 100644 --- a/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp +++ b/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp @@ -686,57 +686,11 @@ pcl::SupervoxelClustering::getMaxLabel () const return max_label; } -namespace pcl -{ - namespace octree - { - //Explicit overloads for RGB types - template<> - void - pcl::octree::OctreePointCloudAdjacencyContainer::VoxelData>::addPoint (const pcl::PointXYZRGB &new_point); - - template<> - void - pcl::octree::OctreePointCloudAdjacencyContainer::VoxelData>::addPoint (const pcl::PointXYZRGBA &new_point); - - //Explicit overloads for RGB types - template<> void - pcl::octree::OctreePointCloudAdjacencyContainer::VoxelData>::computeData (); - - template<> void - pcl::octree::OctreePointCloudAdjacencyContainer::VoxelData>::computeData (); - - //Explicit overloads for XYZ types - template<> - void - pcl::octree::OctreePointCloudAdjacencyContainer::VoxelData>::addPoint (const pcl::PointXYZ &new_point); - - template<> void - pcl::octree::OctreePointCloudAdjacencyContainer::VoxelData>::computeData (); - } -} - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// namespace pcl -{ - - template<> void - pcl::SupervoxelClustering::VoxelData::getPoint (pcl::PointXYZRGB &point_arg) const; - - template<> void - pcl::SupervoxelClustering::VoxelData::getPoint (pcl::PointXYZRGBA &point_arg ) const; - - template void - pcl::SupervoxelClustering::VoxelData::getPoint (PointT &point_arg ) const - { - //XYZ is required or this doesn't make much sense... - point_arg.x = xyz_[0]; - point_arg.y = xyz_[1]; - point_arg.z = xyz_[2]; - } - +{ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template void pcl::SupervoxelClustering::VoxelData::getNormal (Normal &normal_arg) const diff --git a/segmentation/include/pcl/segmentation/supervoxel_clustering.h b/segmentation/include/pcl/segmentation/supervoxel_clustering.h index e9e8018bf55..4c6a4b76a6e 100644 --- a/segmentation/include/pcl/segmentation/supervoxel_clustering.h +++ b/segmentation/include/pcl/segmentation/supervoxel_clustering.h @@ -143,11 +143,33 @@ namespace pcl owner_ (nullptr) {} +#ifdef DOXYGEN_ONLY /** \brief Gets the data of in the form of a point * \param[out] point_arg Will contain the point value of the voxeldata */ void getPoint (PointT &point_arg) const; +#else + template = true> void + getPoint (PointT &point_arg) const + { + point_arg.rgba = static_cast(rgb_[0]) << 16 | + static_cast(rgb_[1]) << 8 | + static_cast(rgb_[2]); + point_arg.x = xyz_[0]; + point_arg.y = xyz_[1]; + point_arg.z = xyz_[2]; + } + + template = true> void + getPoint (PointT &point_arg ) const + { + //XYZ is required or this doesn't make much sense... + point_arg.x = xyz_[0]; + point_arg.y = xyz_[1]; + point_arg.z = xyz_[2]; + } +#endif /** \brief Gets the data of in the form of a normal * \param[out] normal_arg Will contain the normal value of the voxeldata diff --git a/segmentation/src/supervoxel_clustering.cpp b/segmentation/src/supervoxel_clustering.cpp index 663b0eda7c1..821901ec540 100644 --- a/segmentation/src/supervoxel_clustering.cpp +++ b/segmentation/src/supervoxel_clustering.cpp @@ -49,6 +49,10 @@ #include #include +template class PCL_EXPORTS pcl::SupervoxelClustering; +template class PCL_EXPORTS pcl::SupervoxelClustering; +template class PCL_EXPORTS pcl::SupervoxelClustering; + namespace pcl { namespace octree @@ -135,31 +139,6 @@ namespace pcl ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -namespace pcl -{ - template<> void - pcl::SupervoxelClustering::VoxelData::getPoint (pcl::PointXYZRGB &point_arg) const - { - point_arg.rgba = static_cast(rgb_[0]) << 16 | - static_cast(rgb_[1]) << 8 | - static_cast(rgb_[2]); - point_arg.x = xyz_[0]; - point_arg.y = xyz_[1]; - point_arg.z = xyz_[2]; - } - - template<> void - pcl::SupervoxelClustering::VoxelData::getPoint (pcl::PointXYZRGBA &point_arg ) const - { - point_arg.rgba = static_cast(rgb_[0]) << 16 | - static_cast(rgb_[1]) << 8 | - static_cast(rgb_[2]); - point_arg.x = xyz_[0]; - point_arg.y = xyz_[1]; - point_arg.z = xyz_[2]; - } -} - using VoxelDataT = pcl::SupervoxelClustering::VoxelData; using VoxelDataRGBT = pcl::SupervoxelClustering::VoxelData; using VoxelDataRGBAT = pcl::SupervoxelClustering::VoxelData; @@ -168,10 +147,6 @@ using AdjacencyContainerT = pcl::octree::OctreePointCloudAdjacencyContainer; using AdjacencyContainerRGBAT = pcl::octree::OctreePointCloudAdjacencyContainer; -template class pcl::SupervoxelClustering; -template class pcl::SupervoxelClustering; -template class pcl::SupervoxelClustering; - template class pcl::octree::OctreePointCloudAdjacencyContainer; template class pcl::octree::OctreePointCloudAdjacencyContainer; template class pcl::octree::OctreePointCloudAdjacencyContainer; From df65f21baad5c7601fbcb7a2809da377d818f638 Mon Sep 17 00:00:00 2001 From: Markus Vieth Date: Wed, 7 Aug 2024 11:02:38 +0200 Subject: [PATCH 2/4] Try different solution for RangeImage --- common/include/pcl/range_image/range_image.h | 6 +----- common/src/range_image.cpp | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/common/include/pcl/range_image/range_image.h b/common/include/pcl/range_image/range_image.h index 92cabf613e1..f611bff63d4 100644 --- a/common/include/pcl/range_image/range_image.h +++ b/common/include/pcl/range_image/range_image.h @@ -51,11 +51,7 @@ namespace pcl * \author Bastian Steder * \ingroup range_image */ -#if defined _WIN32 || defined WINCE || defined __MINGW32__ class RangeImage : public pcl::PointCloud -#else - class PCL_EXPORTS RangeImage : public pcl::PointCloud -#endif { public: // =====TYPEDEFS===== @@ -75,7 +71,7 @@ namespace pcl /** Constructor */ PCL_EXPORTS RangeImage (); /** Destructor */ - PCL_EXPORTS virtual ~RangeImage () = default; + PCL_EXPORTS virtual ~RangeImage (); // =====STATIC VARIABLES===== /** The maximum number of openmp threads that can be used in this class */ diff --git a/common/src/range_image.cpp b/common/src/range_image.cpp index 91ba59bf5fc..966b85eab4b 100644 --- a/common/src/range_image.cpp +++ b/common/src/range_image.cpp @@ -113,6 +113,8 @@ RangeImage::RangeImage () : unobserved_point.range = -std::numeric_limits::infinity (); } +RangeImage::~RangeImage () = default; + ///////////////////////////////////////////////////////////////////////// void RangeImage::reset () From 0fc4ce9fc10de15a4f089c346e0891b390d1da77 Mon Sep 17 00:00:00 2001 From: Markus Vieth Date: Wed, 7 Aug 2024 14:55:23 +0200 Subject: [PATCH 3/4] Add PCL_EXPORTS on static data (needed for gcc/Release configuration --- common/include/pcl/range_image/range_image.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/include/pcl/range_image/range_image.h b/common/include/pcl/range_image/range_image.h index f611bff63d4..6392b723a14 100644 --- a/common/include/pcl/range_image/range_image.h +++ b/common/include/pcl/range_image/range_image.h @@ -782,10 +782,10 @@ namespace pcl // =====STATIC PROTECTED===== - static const int lookup_table_size; - static std::vector asin_lookup_table; - static std::vector atan_lookup_table; - static std::vector cos_lookup_table; + PCL_EXPORTS static const int lookup_table_size; + PCL_EXPORTS static std::vector asin_lookup_table; + PCL_EXPORTS static std::vector atan_lookup_table; + PCL_EXPORTS static std::vector cos_lookup_table; /** Create lookup tables for trigonometric functions */ static void createLookupTables (); From 8c6449343393325147d5f32f9d6d401f7277201e Mon Sep 17 00:00:00 2001 From: Markus Vieth Date: Mon, 12 Aug 2024 11:35:12 +0200 Subject: [PATCH 4/4] Disable hidden visibility by default --- cmake/pcl_options.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/pcl_options.cmake b/cmake/pcl_options.cmake index e5b968634f2..1c9781e00b8 100644 --- a/cmake/pcl_options.cmake +++ b/cmake/pcl_options.cmake @@ -124,7 +124,7 @@ option(PCL_DISABLE_GPU_TESTS "Disable running GPU tests. If disabled, tests will option(PCL_DISABLE_VISUALIZATION_TESTS "Disable running visualizations tests. If disabled, tests will still be built." OFF) # This leads to smaller libraries, possibly faster code, and fixes some bugs. See https://gcc.gnu.org/wiki/Visibility -option(PCL_SYMBOL_VISIBILITY_HIDDEN "Hide all binary symbols by default, export only those explicitly marked (gcc and clang only). Experimental!" ON) +option(PCL_SYMBOL_VISIBILITY_HIDDEN "Hide all binary symbols by default, export only those explicitly marked (gcc and clang only). Experimental!" OFF) mark_as_advanced(PCL_SYMBOL_VISIBILITY_HIDDEN) if(PCL_SYMBOL_VISIBILITY_HIDDEN) set(CMAKE_CXX_VISIBILITY_PRESET hidden)