-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow hidden visibility default on gcc/clang #5779
Allow hidden visibility default on gcc/clang #5779
Conversation
dd32d31
to
4276c3a
Compare
4276c3a
to
9b1508d
Compare
eaab75c
to
a8517d7
Compare
a8517d7
to
cb713cc
Compare
This would close #1913 FYI. |
f6767fb
to
9f734b2
Compare
16e3e28
to
572c341
Compare
79cc27b
to
c2442d5
Compare
0710e85
to
a4be328
Compare
a4be328
to
c712a44
Compare
You should move the key function (in this case virtual destructor) into a CPP file. |
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. |
Should/can we export the entire range_image class instead of a bunch of "selected" members? |
When I tested that, it lead to problems with MSVC (see also what I wrote above under "Range Image" but crossed out because I switched to a different solution). Basically, when range_image.h is included in another PCL module (e.g. io) and the whole class is marked as PCL_EXPORTS, then MSVC expects a definition of RangeImage's four static members in io as well (like the definition in range_image.cpp). In that case, there seems to be nothing that indicates that RangeImage is exported from common, and not io. I am actually wondering if it wouldn't be "more correct" to have multiple macros PCL_COMMON_EXPORTS, PCL_IO_EXPORTS, PCL_FILTERS_EXPORTS, etc instead of just PCL_EXPORTS for all modules. Perhaps we could look into this in the future. |
Every library must have its own |
Exporting the whole class should work on all platforms. I suspect that the reason why it doesn't work is because of the wrong exporting logic on Windows (see my previous comment). |
That was my impression as well while reading into MSVC's exporting system. But if that is the case, why have there never been any problems with the current shared I would suggest to merge this pull request as soon as possible since I have been working on this for over a year and it would be nice to have this feature finally merged. Assuming of course, that we all agree that there is no regression compared to the master branch, no new bugs are introduced, nothing is made worse. |
I think its good to merge! I wonder why there have been no issues with the Exceptions and why those need export macro, but I guess they just haven't been used on windows 😄 I have fiddled around with cmakes generate_export_header and found out that it adds: __declspec (dllimport) to the else case. When I compiled with that and using ie PointCloud in a subproject I got all kinds of linking errors. And seemingly you shouldn't export templated classes (kinda makes sense though 😁) - but the various instantiations that we make, can be exported. Also as of what I understood, static member variables are not allowed to have an initial value, but its advised to set the value in a .cpp file and it could be done in, ie. a initialize method. I haven't tried it yet though (that might be applicable to the range_image?) |
Hmm I just tried to use an pcl::PCLException and it compiles fine without the export flags. Also according to https://stackoverflow.com/questions/64506244/how-do-i-export-class-that-fully-defined-in-header-file - since it fully defined in the header file, there is nothing to export? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we retest without PCL_EXPORT for all the exceptions?
I added PCL_EXPORTS to the exceptions because the section "Problems with C++ exceptions" in https://gcc.gnu.org/wiki/Visibility warned that all user defined exceptions must be marked as |
Hm okay. I just tested with an application using PCLException, but not the example with libB throwing a exception defined in LibA and handled in libC 😅 |
I tested with GCC and printed the symbols in pcl_common with the
Without
The second column is the symbol type, a lowercase letter means that the symbol is local, while an uppercase letter means that it is global (external). This indicates that marking the exceptions with |
I have tested both on windows and ubuntu (24.04 dev docker), where I make a small application that calls code, that makes an exception in the common .dll/.so.
Generally though, I think we would get some linker errors, if we add the However, if Whole Program Optimization is enabled, this can be achieved as well (which is normally the case, except if we compile with cuda/gpu modules atm, since that had a bug with an old thrust library). I tried with the |
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 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 thatPCL_EXPORTS
is missing somewhere. I think for now, it is better to leave this disabled by default, and only encourage users who are fine with experimental features to enable it. In the future, we might then enable it for everyone.Suggested read: https://gcc.gnu.org/wiki/Visibility
Range image
A commenter suggested a different solution, now only the four static members need to be marked with
PCL_EXPORTS
.For gcc, I could only get it to work with the wholeIn 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 inRangeImage
class marked asPCL_EXPORTS
(i.e.__attribute__ ((visibility ("default")))
), otherwise I get the linking errorundefined 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 asdllexport
so the compiler seems to expect a definition of the static members (lookup tables) in that module as well.RGB2sRGB_LUT
).Supervoxel clustering
Moved the specializations of
getPoint
to supervoxel_clustering.h, usingtraits::HasColor
. This was necessary to resolve some interdependencies betweenSupervoxelClustering
,OctreePointCloudAdjacencyContainer
, andOctreePointCloudAdjacency
Further changes
PCL_EXPORTS
onTransformationEstimationSVD
again. I added it in a previous PR but noticed now that it was not necessary and caused warnings on MSVC.PCL_EXPORTS
to the static members inRangeImage
, these change might fix also [windows] error linking pcl rangeimage LNK2020 LNK2001 LNK1120 #807 , but I did not test thatRGB
andPointXYZRGB
is not necessary and even creates a warning that the visibility attributes change with this redefinition. The class is tested in https://github.com/PointCloudLibrary/pcl/blob/master/test/filters/test_convolution.cpp with both types__cplusplus
is defined (i.e. whether the program is a C++ program) before doing C++ version checks, because this file is now included in some C source code file via pcl_exports.hLibrary size
Built with GCC 13.2. All CMake options except
CMAKE_BUILD_TYPE
andPCL_SYMBOL_VISIBILITY_HIDDEN
are the default ones