From c19e4845e460c85d96cac15d6aa9e6bdcb4076a3 Mon Sep 17 00:00:00 2001 From: smathis Date: Tue, 12 Aug 2025 08:51:54 +0200 Subject: [PATCH] Hide visibility of sinqController classes --- README.md | 14 +++++++++++++- src/msgPrintControl.h | 19 +++++++++++++++++-- src/sinqAxis.h | 3 ++- src/sinqController.h | 4 ++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2ff0644..ccc9a81 100644 --- a/README.md +++ b/README.md @@ -309,4 +309,16 @@ If your driver uses another driver as a static dependency via git submodule whic - `git commit -m "Update turboPmac to 1.0"` - `git submodule update --init --recursive` -This will update sinqMotor to the version specified in the 1.0 commit of turboPmac. \ No newline at end of file +This will update sinqMotor to the version specified in the 1.0 commit of turboPmac. + +### Exporting symbols + +By default, the symbols of classes and functions are hidden to avoid symbol clashes when loading +multiple shared libraries which use `sinqMotor`. In order to compile this library with exported +symbols, specifiy `-DHIDDEN= ` as a compiler flag (if using the given Makefile, this +needs to be added to the `USR_CFLAGS`). + +Derived libraries can use the same mechanism via the macro `HIDDEN` (defined in `msgPrintControl.h`): +``` +class HIDDEN turboPmacController : public sinqController +``` diff --git a/src/msgPrintControl.h b/src/msgPrintControl.h index a228f8e..a52616c 100644 --- a/src/msgPrintControl.h +++ b/src/msgPrintControl.h @@ -10,12 +10,27 @@ #include #include +/* +The macro "HIDDEN" hides the symbol of the annotated class / function. This is +useful to avoid symbol clashes when loading multiple shared libraries in a +single IOC. To override the hiding, add `-DHIDDEN= ` to your compiler +flags (in this case, the symbols will be exported with their default +visibility). +*/ +#ifndef HIDDEN +#if defined(_WIN32) || defined(__CYGWIN__) +#define HIDDEN +#else +#define HIDDEN __attribute__((visibility("hidden"))) +#endif +#endif + /** * @brief Class to identify a message print location. See the docstring of * `msgPrintControl` on how to use this key. * */ -class msgPrintControlKey { +class HIDDEN msgPrintControlKey { public: std::string controller_; @@ -82,7 +97,7 @@ template <> struct hash { * } * ``` */ -class msgPrintControl { +class HIDDEN msgPrintControl { public: /** * @brief Destroy the msgPrintControl object diff --git a/src/sinqAxis.h b/src/sinqAxis.h index b3b7ffe..3f90f76 100644 --- a/src/sinqAxis.h +++ b/src/sinqAxis.h @@ -9,12 +9,13 @@ Stefan Mathis, November 2024 #ifndef sinqAxis_H #define sinqAxis_H #include "asynMotorAxis.h" +#include "msgPrintControl.h" #include #include struct sinqAxisImpl; -class epicsShareClass sinqAxis : public asynMotorAxis { +class HIDDEN sinqAxis : public asynMotorAxis { public: /** * @brief Construct a new sinqAxis object diff --git a/src/sinqController.h b/src/sinqController.h index c12dd55..f359dd9 100644 --- a/src/sinqController.h +++ b/src/sinqController.h @@ -20,9 +20,9 @@ Stefan Mathis, November 2024 #define AbsoluteEncoder "absolute" #define NoEncoder "none" -struct sinqControllerImpl; +struct HIDDEN sinqControllerImpl; -class epicsShareClass sinqController : public asynMotorController { +class HIDDEN sinqController : public asynMotorController { public: /** * @brief Construct a new sinqController object