Skip to content

Commit

Permalink
fix: Multiple definitions errors with plugin features
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jul 8, 2024
1 parent 27b1a5d commit 12ca4e2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/libimhex/include/hex/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
return nullptr;
}

extern std::vector<hex::Feature> g_features;
[[maybe_unused]] static auto& getFeaturesImpl() {
static std::vector<hex::Feature> features;
return features;
}

#if defined (IMHEX_STATIC_LINK_PLUGINS)
#define IMHEX_PLUGIN_VISIBILITY_PREFIX static
Expand All @@ -48,21 +51,20 @@ extern std::vector<hex::Feature> g_features;
#define IMHEX_FEATURE_ENABLED(feature) WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(IMHEX_PLUGIN_, IMHEX_PLUGIN_NAME), _FEATURE_), feature)
#define IMHEX_DEFINE_PLUGIN_FEATURES() IMHEX_DEFINE_PLUGIN_FEATURES_IMPL()
#define IMHEX_DEFINE_PLUGIN_FEATURES_IMPL() \
extern std::vector<hex::Feature> g_features; \
template<> \
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
static void* getFeatures(); \
}; \
void* PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures() { \
return &g_features; \
return &getFeaturesImpl(); \
} \
std::vector<hex::Feature> g_features = { IMHEX_PLUGIN_FEATURES_CONTENT }
static auto initFeatures = [] { getFeaturesImpl() = std::vector<hex::Feature>({ IMHEX_PLUGIN_FEATURES_CONTENT }); return 0; }()

#define IMHEX_PLUGIN_FEATURES g_features
#define IMHEX_PLUGIN_FEATURES ::getFeaturesImpl()

/**
* This macro is used to define all the required entry points for a plugin.
* Name, Author and Description will be displayed in the in the plugin list on the Welcome screen.
* Name, Author and Description will be displayed in the plugin list on the Welcome screen.
*/
#define IMHEX_PLUGIN_SETUP(name, author, description) IMHEX_PLUGIN_SETUP_IMPL(name, author, description)
#define IMHEX_LIBRARY_SETUP(name) IMHEX_LIBRARY_SETUP_IMPL(name)
Expand Down

0 comments on commit 12ca4e2

Please sign in to comment.