-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Export Data3DPointsData_t class in shared library. #252
Export Data3DPointsData_t class in shared library. #252
Conversation
e53fb42
to
cfe2799
Compare
We depend on the class in our code, hope it's fine to export it.
cfe2799
to
d2ae287
Compare
@@ -744,9 +744,6 @@ namespace e57 | |||
using Data3DPointsData_d [[deprecated( "Will be removed in 4.0. Use Data3DPointsDouble." )]] = | |||
Data3DPointsData_t<double>; | |||
|
|||
extern template struct Data3DPointsData_t<float>; | |||
extern template struct Data3DPointsData_t<double>; | |||
|
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.
This change removes the whole reason for having explicit template instantiation in the cpp file.
What error is the original code giving you? What compiler are you using?
According to everything I looked at w.r.t. Windows said that the way I did it is correct and the CI tests run properly with the shared lib. Maybe there's some other issue that's showing up as a problem with this declaration?
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.
Quick follow-up. I just tried it locally with this compiler:
C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe
The test executable builds and runs without warnings/errors when using E57Format as a shared lib. It uses both Data3DPointsFloat
and Data3DPointsDouble
.
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.
Ok, so my original problem is that Data3DPointsData_t<double>
and Data3DPointsData_t<false>
are hidden in Linux shared library. If I added E57_DLL
at line 747
I got the following Windows build errors:
D:\a\libE57Format\libE57Format\include\E57SimpleData.h(747): error C2220: the following warning is treated as an error
D:\a\libE57Format\libE57Format\include\E57SimpleData.h(747): warning C4910: 'e57::Data3DPointsData_t<float>': '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation
D:\a\libE57Format\libE57Format\include\E57SimpleData.h(748): warning C4910: 'e57::Data3DPointsData_t<double>': '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation
which is about one can't combine extern
and __declspec(dllexport)
at one line. And so I suggested to use E57_DLL
in the cpp
file.
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.
I will verify that the symbol is hidden on Linux tomorrow.
Aha! I thought you were on Windows for some reason.
Yeah - I think the Windows stuff is correct (based on CI & my very limited local testing) - it was confusing to get working because it seems backwards - and I know the macOS version works because that's what I use. I don't have Linux set up so I can't test it other than through CI. That said - the Linux shared lib CI seems to compile cleanly and work with the original code. Are you using gcc? Maybe there's a compiler switch that might be causing this that I need to account for? Can you quote the full error when trying to use the original code?
Typo when writing on GitHub or is that in your code? |
Oh - it would also be interesting to see the contents of |
All right, so the situation is a bit more complicated as I'm using the conan package: conan-io/conan-center-index#19135 where they use With
so as seen,
which seems correct to me. And the content of #ifndef E57_DLL_H
#define E57_DLL_H
#ifdef E57FORMAT_STATIC_DEFINE
# define E57_DLL
# define E57FORMAT_NO_EXPORT
#else
# ifndef E57_DLL
# ifdef E57Format_EXPORTS
/* We are building this library */
# define E57_DLL __attribute__((visibility("default")))
# else
/* We are using this library */
# define E57_DLL __attribute__((visibility("default")))
# endif
# endif
# ifndef E57FORMAT_NO_EXPORT
# define E57FORMAT_NO_EXPORT __attribute__((visibility("hidden")))
# endif
#endif
#ifndef E57FORMAT_DEPRECATED
# define E57FORMAT_DEPRECATED __attribute__ ((__deprecated__))
#endif
#ifndef E57FORMAT_DEPRECATED_EXPORT
# define E57FORMAT_DEPRECATED_EXPORT E57_DLL E57FORMAT_DEPRECATED
#endif
#ifndef E57FORMAT_DEPRECATED_NO_EXPORT
# define E57FORMAT_DEPRECATED_NO_EXPORT E57FORMAT_NO_EXPORT E57FORMAT_DEPRECATED
#endif
#if 0 /* DEFINE_NO_DEPRECATED */
# ifndef E57FORMAT_NO_DEPRECATED
# define E57FORMAT_NO_DEPRECATED
# endif
#endif
// Windows DLLs can't include the extern keyword when declaring templates
#ifdef _MSC_VER
#define TEMPLATE_EXTERN
#else
#define TEMPLATE_EXTERN extern
#endif
// NOTE: This is a generated file. Any changes will be overwritten.
#endif /* E57_DLL_H */ |
Thanks Martin. The reason I'm pushing on this is that I'm seeing an inconsistency between what the CI seems to say and what you're experiencing, so I'd like to figure out exactly what's going on before making changes.
Removing the |
Sure, that's super fine and I think I found the root cause. It's the following thing: diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca34630..844652d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -227,7 +227,7 @@ if ( E57_BUILD_TEST )
# If we are building tests, we need access to all the symbols, so override visibility
set_target_properties( E57Format
PROPERTIES
- CXX_VISIBILITY_PRESET default
+ CMAKE_CXX_VISIBILITY_PRESET default
CMAKE_VISIBILITY_INLINES_HIDDEN OFF
) which the change I can't see the symbols exported in the library:
Does it make sense now? |
Ahh! Not testing what I think I'm testing! 🤦 Changing it from OK good. So can you try one last thing please? Could you please revert the changes to the header so the the only change is adding |
Heh, that happens ;)
Sure.
Yep. If I do that I end up with:
|
So I think I can fix this, however now I get UBSan failures related to Not sure what's going on, but not surprised it's an issue with Xerces. I will check it in on a branch to see if other warnings/errors show up on other compilers. |
Also change testing to not override visibility & to limit some testing on all shared library builds (not just Windows). Working on #252
Thank you very much! |
Actually I'm not sure I can fix this 😆 Seems like conflicts between extern templates and hidden symbol visibility. There are too many combinations of compiler, OS, visibility, and shared/static. Fix one combination and it breaks another. I may remove the |
I cannot get extern templates to work across all of gcc, clang, apple clang, and MSVC when using “hidden” visibility and shared libraries. Fixes #252
I cannot get extern templates to work across all of gcc, clang, apple clang, and MSVC when using “hidden” visibility and shared libraries. Fixes #252
We depend on the class in our code, hope it's fine to export it.